Skip to content
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

Merged
merged 22 commits into from
May 8, 2020
Merged

#764 Fix crash on parse some control chars #771

merged 22 commits into from
May 8, 2020

Conversation

adamfilipow92
Copy link
Contributor

@adamfilipow92 adamfilipow92 commented May 7, 2020

Fixes #764

Fix crash on parse some control chars

Fix crash on parse some control chars
@jan-goral jan-goral changed the title #764 #764 Fix crash on parse some control chars May 7, 2020
@jan-goral jan-goral assigned jan-goral and adamfilipow92 and unassigned jan-goral May 7, 2020
detekt issues fix
""".trimIndent()

parseAllSuitesXml(crashingAllSuitesMessage)
parseOneSuiteXml(crashingOneSuiteMessage)
Copy link
Contributor

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.

Copy link
Contributor Author

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))
Copy link
Contributor

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.

Copy link
Contributor

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()
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

bootstraponline
bootstraponline previously approved these changes May 7, 2020
jan-goral
jan-goral previously approved these changes May 7, 2020

import org.apache.commons.text.StringEscapeUtils

fun fixHtmlCodes(data: String): String {
Copy link
Contributor

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

Copy link
Contributor

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 👍

Copy link
Contributor Author

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"
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added

Copy link
Contributor

@pawelpasterz pawelpasterz left a 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!

jan-goral and others added 3 commits May 8, 2020 13:30
* Fail fast when results-dir is incorrect
Fix crash on parse some control chars
detekt issues fix
Add asserts in test and replace Files.readString to Files.readAllBytes for compability with java 1.8
@adamfilipow92 adamfilipow92 dismissed stale reviews from jan-goral and bootstraponline via df19d79 May 8, 2020 11:30
@adamfilipow92
Copy link
Contributor Author

Please remove should_exists.txt file from PR.

Removed :)

@pawelpasterz
Copy link
Contributor

@adamfilipow92
Nice work! Remember to squash commits before you merge, thanks!

@adamfilipow92 adamfilipow92 merged commit 3d960c7 into master May 8, 2020
@adamfilipow92 adamfilipow92 deleted the bug/#764 branch May 8, 2020 13:24
adamfilipow92 added a commit that referenced this pull request May 13, 2020
* #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]>
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.

Crash on XML parsing
4 participants