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

[SHIRO-530] INI parser does not properly handled backslashes at end o… #209

Closed
wants to merge 2 commits into from
Closed

Conversation

bmarwell
Copy link
Contributor

…f values

  • Replace key-value-splitting with regex
  • obscure disappearing escaping chars - please discuss!

Signed-off-by: Benjamin Marwell bmarwell@gmail.com

Now. If we would not want to break the existing (imho: obscure) way that shiro parses the shiro.ini file, we could introduce a parser strategy pattern.

But as the existing behaviour was not documented (other than tests), I would like to see a discussion about this.

Tests broken on purpose! See here why: SHIRO-530

@bmarwell
Copy link
Contributor Author

bmarwell commented Mar 30, 2020

TODO:

  • document capture groups
  • remove \\ from first capture group. It just makes no sense. Disappearing is unexpected. Or just let it disappear from the key only?
  • to make it more similar to the existing behaviour, we could just strip backsashes from the key. final String key = matcher.group(1).replaceAll("\\\\", "");.
  • Please explain this test (especially it's purpose). It makes no sense imho. This would be the only test failing then.
        test = "Truth\\=Beauty";
        kv = Ini.Section.splitKeyValue(test);
        assertEquals("Truth", kv[0]);
        assertEquals("Beauty", kv[1]);

@fpapon
Copy link
Member

fpapon commented Mar 30, 2020

We have some users that are using backslash in the key:
https://issues.apache.org/jira/browse/SHIRO-684

@bmarwell
Copy link
Contributor Author

?? Why introduce a new future? If you look at the tests, this was never supported and those always got removed.

@bdemers
Copy link
Member

bdemers commented Mar 30, 2020

From SHIRO-530, it looks like we have:

example (as input) result (as java string)
key=value\ key=value\n
key=value\\ key=value\\
key=value\\\ key=value\\
key=value\\\\ key=value\\\\

I would expect the result to be:

example (as input) result (as java string)
key=value\ key=value\n
key=value\\ key=value\\
key=value\\\ key=value\\\n
key=value\\\\ key=value\\\\

As for "Truth\\=Beauty", I would expect that that to be some sort of error or at least a key with no value similar to:

[foobar]
one=one
justAKeyWithoutValue

I'm not saying this is the way it does function, or should just what I personally would expect. (not sure if that helps or hurts this conversation)

…f values

 - Replace key-value-splitting with regex
 - obscure disappearing escaping chars - please discuss!
 - remove escaping backslashes from the first capture group (key) to retain old behaviour.
 - Do not remove escaping baskslashes from the value (new behaviour demanded by SHIRO-530).
 - rearrange and comment tests to reflect old and new, desired behaviour.

Signed-off-by: Benjamin Marwell <bmarwell@gmail.com>
@bmarwell
Copy link
Contributor Author

As for "Truth\\=Beauty", I would expect that that to be some sort of error or at least a key with no value similar to:

Thanks for the input @bdemers, I had the very same thoughts! The new force-pushed commit:

  • Will throw an IllegalArgumentException for Key\\=Value.
  • Will (as before!) remove all backslashes from the key.
  • Will not (new behaviour) remove any backslashes from the value. The continuation backslash not included.

Actually, what @fpapon pointed out by posting the link: The XML config DOES allow backslashes in the key, where the Ini never allowed to do so. Please review my new commit which reflects these changes. I moved the tests a bit and commented them, so we can see what would change.
Please keep in mind: Neither the current nor the desired/expected behaviour is currently documented, not even in the code! It is just the tests!

@fpapon
Copy link
Member

fpapon commented Mar 31, 2020

+1 for me, if we think it's not possible (ini specs) to have \ in the key, just throw an exception.
@bmhm Thanks for taking care of this ;)

…f values

 - Replace key-value-splitting with regex
 - remove escaping backslashes from the first capture group (key) to retain old behaviour.
 - Do not remove escaping baskslashes from the value (new behaviour demanded by SHIRO-530).
 - rearrange and comment tests to reflect old and new, desired behaviour.
 - seperator char can be preceeded or followed by whitespace.

Signed-off-by: Benjamin Marwell <bmarwell@gmail.com>
@bmarwell
Copy link
Contributor Author

bmarwell commented Mar 31, 2020

I am not so sure about this commit. It would be possible, in theory, that someone misused the escaping backslashes (which disappeared from the value) as indendation:

key    =    value\
          \\1

In the old word, this was "key" => "value1", but in the new one it would be "value\\1".

But then, it was never documented.

@bmarwell
Copy link
Contributor Author

bmarwell commented Apr 1, 2020

Superseeded by #210

@bmarwell bmarwell closed this Apr 1, 2020
@bmarwell bmarwell deleted the SHIRO-530 branch May 11, 2020 08:49
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.

None yet

3 participants