-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#764 Fix crash on parse some control chars #771
Changes from 2 commits
f182c8c
6be0d1f
10a1799
9387a48
ee575ae
b36c3b5
9b025ac
77b574b
1ba4a77
795f9e2
58074c3
4a484aa
9a6f328
2e9f925
da1fa2a
dfd80fb
793b97e
6f8fc9e
5350fc3
df19d79
6c60453
e757e02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ftl.reports.xml.preprocesor | ||
|
||
import org.apache.commons.text.StringEscapeUtils | ||
|
||
fun fixHtmlCodes(data: String): String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO expressions > blocks ;)
unions are not mandatory for those values There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am also for @jan-gogo version 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Changed to better version :) |
||
val isoHtmlCodesToReplace = listOf(0x00..0x1F).union(listOf(0x7F..0x9F)).flatten() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some document we can reference in a comment about where these magic numbers come from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other thought I had is, are we sure there's no helper already defined in a library that does what we need? Maybe this is a special case so the custom code is justified. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I this case we need to get list of control chars and convert them to html codes with avoid white chars. I cant find method doing this. |
||
.map { StringEscapeUtils.escapeXml11(it.toChar().toString()) }.filter { it.startsWith("&#") } | ||
|
||
var fixedStr = data | ||
for (isoControlCode in isoHtmlCodesToReplace) { | ||
fixedStr = fixedStr.replace(isoControlCode, "") | ||
} | ||
return fixedStr | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,8 @@ junit.framework.Assert.fail(Assert.java:50)</failure> | |
|
||
@Test | ||
fun `merge ios`() { | ||
val merged = parseAllSuitesXml(iosPassXml).merge(parseAllSuitesXml(iosFailXml)).xmlToString().normalizeLineEnding() | ||
val merged = | ||
parseAllSuitesXml(iosPassXml).merge(parseAllSuitesXml(iosFailXml)).xmlToString().normalizeLineEnding() | ||
val expected = """ | ||
<?xml version='1.0' encoding='UTF-8' ?> | ||
<testsuites> | ||
|
@@ -94,7 +95,8 @@ junit.framework.Assert.fail(Assert.java:50)</failure> | |
|
||
@Test | ||
fun `Merge iOS large time`() { | ||
val merged = parseAllSuitesXml(iosLargeNum).merge(parseAllSuitesXml(iosLargeNum)).xmlToString().normalizeLineEnding() | ||
val merged = | ||
parseAllSuitesXml(iosLargeNum).merge(parseAllSuitesXml(iosLargeNum)).xmlToString().normalizeLineEnding() | ||
|
||
val expected = """ | ||
<?xml version='1.0' encoding='UTF-8' ?> | ||
|
@@ -423,7 +425,8 @@ junit.framework.Assert.fail(Assert.java:50)</failure> | |
// * c() failed in newRun and passed in oldRun. timing info copied over from oldRun | ||
// * d() was skipped in newRun and successful in oldRun. d() is excluded from the merged result | ||
|
||
val merged = parseAllSuitesXml(newRun).mergeTestTimes(parseAllSuitesXml(oldRun)).xmlToString().normalizeLineEnding() | ||
val merged = | ||
parseAllSuitesXml(newRun).mergeTestTimes(parseAllSuitesXml(oldRun)).xmlToString().normalizeLineEnding() | ||
val expected = """ | ||
<?xml version='1.0' encoding='UTF-8' ?> | ||
<testsuites> | ||
|
@@ -437,4 +440,32 @@ junit.framework.Assert.fail(Assert.java:50)</failure> | |
""".trimIndent() | ||
assertThat(merged).isEqualTo(expected) | ||
} | ||
@Test | ||
fun `parse ftl quirks`() { | ||
val crashingAllSuitesMessage = """ | ||
<?xml version='1.0' encoding='UTF-8' ?> | ||
<testsuites> | ||
<testsuite name="EarlGreyExampleSwiftTests" tests="3" failures="0" errors="0" skipped="0" time="10.0" hostname="localhost"> | ||
<testcase name="a()" classname="a" time="1.0"> | ||
<failure> java.net.ConnectException: Failed to connect to ... at (Coroutine boundary.()</failure> | ||
</testcase> | ||
<testcase name="b()" classname="b" time="2.0"/> | ||
<testcase name="c()" classname="c" time="7.0"/> | ||
</testsuite> | ||
</testsuites> | ||
""".trimIndent() | ||
val crashingOneSuiteMessage = """ | ||
<?xml version='1.0' encoding='UTF-8' ?> | ||
<testsuite name="EarlGreyExampleSwiftTests" tests="3" failures="0" errors="0" skipped="0" time="10.0" hostname="localhost"> | ||
<testcase name="a()" classname="a" time="1.0"> | ||
<failure> java.net.ConnectException: Failed to connect to ... at (Coroutine boundary.()</failure> | ||
</testcase> | ||
<testcase name="b()" classname="b" time="2.0"/> | ||
<testcase name="c()" classname="c" time="7.0"/> | ||
</testsuite> | ||
""".trimIndent() | ||
|
||
parseAllSuitesXml(crashingAllSuitesMessage) | ||
parseOneSuiteXml(crashingOneSuiteMessage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also assert that the parsed value matches the expected value? Currently this test will pass as long as parsing doesn't fail. We probably want to assert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have right, Im add asserts and split tests to two. One for one suite and one for all suites |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add here link to repo or equivalent, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added