Skip to content

Fix #125 invalid character (backspace) in output#235

Open
pschneider wants to merge 1 commit into
MobileNativeFoundation:masterfrom
pschneider:fix-backspace-in-output
Open

Fix #125 invalid character (backspace) in output#235
pschneider wants to merge 1 commit into
MobileNativeFoundation:masterfrom
pschneider:fix-backspace-in-output

Conversation

@pschneider

@pschneider pschneider commented Jan 7, 2018

Copy link
Copy Markdown
Contributor

If you clear text in a UITest by pressing backspace, Xcode logs output into console with the UTF-8 character \x08.

This results into the following error message when parsing JUnit output:

org.dom4j.DocumentException: Error on line 496 of document  : An invalid XML character (Unicode: 0x8) was found in the element content of the document. Nested exception: An invalid XML character (Unicode: 0x8) was found in the element content of the document.

To fix this, I’ve replaced the character with the HTML Entity counterpart:

t =    10.54s Type '' into "TestTextField" TextField

This fixes #125.

As I didn’t write any production Objective-C code yet as I started with Swift only please let me know if there’s anything I can improve or needs to be changed.

I couldn’t find any specific unit test for this method to adjust. If there is any I would try to make it test my change. Otherwise I could also provide an XML file with one test case where this specific problem occurs.

@pschneider

Copy link
Copy Markdown
Contributor Author

Just ran the change on our CI and it looks like it still reports the error even though the XML file only contains the HTML entities. Will check why...

@pschneider

Copy link
Copy Markdown
Contributor Author

So it looks like even though the XML contains only the HTML entities, it's not possible to parse the file. Replacing the backspace characters \x08 with an empty string seems to work just fine.

Should we go with this solution?

[string replaceOccurrencesOfString:@"\x08" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [string length])];

@oliverhu

oliverhu commented Jan 8, 2018

Copy link
Copy Markdown
Member

replace \x08 with empty string doesn't sounds good. how about replace \x08 with \\x08. To add a unit test, check https://github.com/linkedin/bluepill/blob/master/Bluepill-cli/BPInstanceTests/BPTreeParserTests.m

@mbalex

mbalex commented Jan 10, 2018

Copy link
Copy Markdown
Contributor

we have the same issue, so I search a bit and found this:
https://en.wikipedia.org/wiki/Valid_characters_in_XML
https://stackoverflow.com/questions/397250/unicode-regex-invalid-xml-characters

valid characters are [\u0009\u000a\u000d\u0020-\uD7FF\uE000-\uFFFD]

I would propose to go through each character, and if you find them not being valid (see regex) then replace them with their escaped value as olverhu suggested for the \x08 case.

@jmkk

jmkk commented May 23, 2019

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Pull request contains merge conflicts.

@chenxiao0228

Copy link
Copy Markdown
Collaborator

Is this still an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test result parsing error

5 participants