Superweird single quote error with native textfield on iOS...

Hi,

The code below creates a native textfield with a listener plus a text object. If I run it on an iOS device (11.2.5) and type a single quote (’) in the textfield, the text object will correctly display a single quote, but the content of the textfield will NOT be a single quote but \M-b\M^@\M^Y.

Yes, I’m serious. All other special characters will display correctly but not the single quote. To make sure that this was not just a “print to console thing”, I used the utf8 library to search the text string and it is indeed \M-b\M^@\M^Y.

How is this possible? Has anyone else seen this?

 local myText = display.newText({ text = "", x = 300, y = 700, height = 0, align = "left", font = native.systemFont, fontSize = 60 }) myText:setFillColor(1, 1, 1) local function listener(event) if (event.phase == "editing") then myText.text = event.text .. properties.cursorCharacter print(event.text) elseif (event.phase == "submitted") then print(event.target.text) end return true end local textField = native.newTextField(display.contentCenterX, 300, 200, 100) textField.isSecure = false textField.hasBackground = true textField.maxCharacters = 100 textField.inputType = "default" textField:setReturnKey("done") textField:addEventListener("userInput", listener)

I have tried to find a workaround by using the gsub pattern matching to find \M-b\M^@\M^Y and replace it with a single quote. In the simulator, the pattern matching works, but not on a device…

Has anyone tried to run the code I posted? Do you get the same result?

By the way, I have filed a bug report since I believe this is a bug in the way Corona “extracts” the content of the native textfield, rather than a bug in the native textfield itself.

Could you be getting a UTF-8 character in the text field instead of a pure ASCII single quote?

I have several keyboards enabled on my iPhone and I’m constantly looking down to find myself on the Spanish or French keyboard and that does impact what symbols are getting entered into the field.

Rob

I did some more googling and I was thinking of the iOS ”smart punctuation” functionality. Apparently, this is something that a lot of developers (including me) are frustrated with since it “distorts” the input from text fields. I tried to disable the smart punctuation functionality and the error disappeared. When using event.text in the edit phase I get the following values using string.byte() 

  • Smart punctuation OFF = 39 (ascii for single quote)
  • Smart punctuation ON = 226 (ascii for “Letter O with circumflex accent”)

It seems that iOS somehow “hijacks” the ascii value of another character to use for its replacement. However, when using event.newCharacters() in the edit phase, I get 39 regardless of whether smart punctuation is on or off.

 

Hence, there are two problems here:

  1. event.text and event.newCharacters “read” different ascii values from the native texfield.
  2. the replacement made by the smart punctuation functionality fools Corona when reading the complete text content from a textfield.

As I said in my previous post, I have filed a bug report (13948306) about this but since I cannot edit the report I would like to ask someone from Corona staff to please enter the above into the bug description. I don’t know if this can be fixed in Corona or if this is an iOS thing but I’d like your engineers to please have a look at it since it is a problem for the Corona users in either case. 

I have tried to find a workaround by using the gsub pattern matching to find \M-b\M^@\M^Y and replace it with a single quote. In the simulator, the pattern matching works, but not on a device…

Has anyone tried to run the code I posted? Do you get the same result?

By the way, I have filed a bug report since I believe this is a bug in the way Corona “extracts” the content of the native textfield, rather than a bug in the native textfield itself.

Could you be getting a UTF-8 character in the text field instead of a pure ASCII single quote?

I have several keyboards enabled on my iPhone and I’m constantly looking down to find myself on the Spanish or French keyboard and that does impact what symbols are getting entered into the field.

Rob

I did some more googling and I was thinking of the iOS ”smart punctuation” functionality. Apparently, this is something that a lot of developers (including me) are frustrated with since it “distorts” the input from text fields. I tried to disable the smart punctuation functionality and the error disappeared. When using event.text in the edit phase I get the following values using string.byte() 

  • Smart punctuation OFF = 39 (ascii for single quote)
  • Smart punctuation ON = 226 (ascii for “Letter O with circumflex accent”)

It seems that iOS somehow “hijacks” the ascii value of another character to use for its replacement. However, when using event.newCharacters() in the edit phase, I get 39 regardless of whether smart punctuation is on or off.

 

Hence, there are two problems here:

  1. event.text and event.newCharacters “read” different ascii values from the native texfield.
  2. the replacement made by the smart punctuation functionality fools Corona when reading the complete text content from a textfield.

As I said in my previous post, I have filed a bug report (13948306) about this but since I cannot edit the report I would like to ask someone from Corona staff to please enter the above into the bug description. I don’t know if this can be fixed in Corona or if this is an iOS thing but I’d like your engineers to please have a look at it since it is a problem for the Corona users in either case.