-
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
Conversation
detekt issues fix
""".trimIndent() | ||
|
||
parseAllSuitesXml(crashingAllSuitesMessage) | ||
parseOneSuiteXml(crashingOneSuiteMessage) |
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.
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 <failure>...
is decoded correctly as well.
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.
You have right, Im add asserts and split tests to two. One for one suite and one for all suites
Add asserts in test and replace Files.readString to Files.readAllBytes for compability with java 1.8
if (!path.toFile().exists()) throw RuntimeException("$path doesn't exist!") | ||
return Files.readAllBytes(path) | ||
return String(Files.readAllBytes(path)) |
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.
I'd like to merge #767 before merging this pull request.
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.
I'd like to merge #767 before merging this pull request.
Done
import org.apache.commons.text.StringEscapeUtils | ||
|
||
fun fixHtmlCodes(data: String): String { | ||
val isoHtmlCodesToReplace = listOf(0x00..0x1F).union(listOf(0x7F..0x9F)).flatten() |
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.
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 comment
The 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 comment
The 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.
About magic numbers: Im added enum with I hope intuitive names. Enum on the top has comment about destination and link to utf-8 table to prove my idea.
</testsuites> | ||
""".trimIndent() | ||
val oneSuiteXml = parseOneSuiteXml(crashingOneSuiteMessage).xmlToString().trimIndent() | ||
Assert.assertEquals("One Suite Messages should be the same!", expectedOneSuiteMessage, oneSuiteXml) |
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.
The tests look great! Thanks for updating these.
detekt issues fix
Add asserts in test and replace Files.readString to Files.readAllBytes for compability with java 1.8
|
||
import org.apache.commons.text.StringEscapeUtils | ||
|
||
fun fixHtmlCodes(data: String): String { |
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.
IMO expressions > blocks ;)
fun fixHtmlCodes(data: String): String = listOf(
UtfControlCharRanges.CONTROL_TOP_START.charValue..UtfControlCharRanges.CONTROL_TOP_END.charValue,
UtfControlCharRanges.CONTROL_BOTTOM_START.charValue..UtfControlCharRanges.CONTROL_BOTTOM_END.charValue
).flatten()
.map { StringEscapeUtils.escapeXml11(it.toChar().toString()) }
.filter { it.startsWith("&#") }
.fold(data) { fixedStr: String, isoControlCode: String -> fixedStr.replace(isoControlCode, "") }
unions are not mandatory for those values
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.
I am also for @jan-gogo version 👍
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.
Thanks! Changed to better version :)
@@ -74,6 +74,8 @@ object Versions { | |||
|
|||
// https://github.com/mockk/mockk | |||
const val MOCKK = "1.9.3" | |||
|
|||
const val COMMON_TEXT = "1.7" |
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
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 remove should_exists.txt
file from PR.
For the future PRs, let's rebase branch once new commits have appeared in master. I think it's good to have PR up-to-date with master in general. It could be just me but in you PR i see also code from @jan-gogo PR a that was a bit confusing.
Anyway, thanks!
* Fail fast when results-dir is incorrect
detekt issues fix
Add asserts in test and replace Files.readString to Files.readAllBytes for compability with java 1.8
remove should_exists
df19d79
Removed :) |
@adamfilipow92 |
* #764 Fix crash on parse some control chars * #764 detekt issues fix detekt issues fix * Asserts in tests Add asserts in test and replace Files.readString to Files.readAllBytes for compability with java 1.8 * Add documentation of magicial numers * set name of UtfControlChars enum to UtfControlCharRanges * #764 Fix crash on parse some control chars * #764 detekt issues fix detekt issues fix * Asserts in tests Add asserts in test and replace Files.readString to Files.readAllBytes for compability with java 1.8 * Add documentation of magicial numers * set name of UtfControlChars enum to UtfControlCharRanges * Detekt suggestions * Create should_exists.txt * #764 Fix crash on parse some control chars * #764 detekt issues fix detekt issues fix * Asserts in tests Add asserts in test and replace Files.readString to Files.readAllBytes for compability with java 1.8 * Add documentation of magicial numers * set name of UtfControlChars enum to UtfControlCharRanges * Fail fast when results-dir is incorrect (#772) * Fail fast when results-dir is incorrect * #764 Change XmlPreprocessor more functional and remove should_exists * Add info about issue to release notes Co-authored-by: Adam <[email protected]> Co-authored-by: Jan Góral <[email protected]>
Fixes #764
Fix crash on parse some control chars