Skip to content

Conversation

@jnyrup
Copy link
Member

@jnyrup jnyrup commented Dec 30, 2018

Unescape is the inverse of Escape, such that str == Unescape(Escape(str)).
But it is problematic if the escaped pattern already exists in the non-escaped string, as calls to Escape and Unescape doesn't seem to be balanced(?).

It's difficult to fix this properly, as Unescape would need to know if some substring was escaped or not.
The approach here is based on the assumption that no one ever uses the ASCII character 0x1B (arbitrarily chosen).
Even though that is not universally true, I believe that character is less used than \.
By surrounding the escaped string with 0x1B we can now see when a substring was escaped, and also guard against double escaping.

Two tests now fails, as Unescape is not called on the escaped string, so it still contains 0x1B.
When_element_has_attributes_it_should_include_them_in_the_output When_element_has_child_element_it_should_not_include_them_in_the_output
I'm not sure if it's a problem though.

Fixes #986

@jnyrup jnyrup changed the title [WIP] Fix (un)escaping when building message Fix (un)escaping when building message Jan 7, 2019
@jnyrup jnyrup requested a review from dennisdoomen January 7, 2019 15:45
@dennisdoomen
Copy link
Member

One alternative, albeit more difficult to do, would require us to introduce an more specialized string class that tracks whether something is escaped or not.

@jnyrup
Copy link
Member Author

jnyrup commented Jan 7, 2019

Just tried to remove the replacement of \r, \n and \" from both Escape and Unescape and only the same two tests as above failed.

Unescape was introduced in b444a39 with no tests
and Escape was introduced in 7662fe3.
So now I'm getting curious about what problem the replacement actually solves, as no tests fails when removing it.

@dennisdoomen
Copy link
Member

Actually, it was introduced as part of #705, so I guess it had to do that stuff didn't get formatted correctly. I also remember plenty of cases where FA crashed when somebody used a { or } in their message.

@dennisdoomen
Copy link
Member

Looks like the build is failing

@jnyrup
Copy link
Member Author

jnyrup commented Jan 23, 2019

The two failing tests asserts that the output is escaped.
I'm uncertain if that is a strict requirement or just a too strict matching assertion.

My test above with (un)escaping still escaped { and } as there are multiple tests exercising that.
I only removed (un)escaping of \r, \n and \" and that only failed to two tests that currently fails.
I've tried searching the issue/pull history but I couldn't find issues describing escaping those three characters.

@jnyrup jnyrup changed the title Fix (un)escaping when building message (un)escaping when building message Jan 23, 2019
@jnyrup jnyrup changed the title (un)escaping when building message Fix (un)escaping when building message Jan 23, 2019
@jnyrup
Copy link
Member Author

jnyrup commented Jan 23, 2019

@dennisdoomen I've updated the PR.
The failing test is a timing related test.

Copy link
Member

@dennisdoomen dennisdoomen left a comment

Choose a reason for hiding this comment

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

Honestly, I don't have a clue whether this will break anything. We'll have to see.

@dennisdoomen
Copy link
Member

Any reason not to merge it?

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.

Backslashes in subject or expected result are not correctly shown in the message

2 participants