Skip to content

Conversation

@51-code
Copy link
Contributor

@51-code 51-code commented Feb 24, 2025

Fixes #40 .

Previously ArgsConfiguration supported a selected set of characters in the key and any characters in the value of the argument. This had led to many PRs adding more supported characters to the regex as they've been needed.

This PR introduces a regex just checks that the argument is in the "key=value" format (in other words, checks that there is something before and after an equals sign). After evaluating the object, there really is no need to check for illegal characters and the user might have specific needs for the key anyways which is not for the object to restrict.

Added a test for the case where an argument is just the equals sign.

@51-code 51-code added the feature Existing feature label Feb 24, 2025
@51-code 51-code requested a review from elliVM February 24, 2025 08:51
@51-code 51-code self-assigned this Feb 24, 2025
elliVM
elliVM previously approved these changes Feb 24, 2025
Copy link

@elliVM elliVM left a comment

Choose a reason for hiding this comment

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

Looks good thanks!

@51-code 51-code requested a review from kortemik February 24, 2025 10:07

if (args.length != 0) {
final Pattern ptn = Pattern.compile("([A-Za-z.\\-_]+)(=.+)");
final Pattern ptn = Pattern.compile("(.+)(=.+)");
Copy link
Member

Choose a reason for hiding this comment

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

this allows foo=bar=biz as an assignment where key is foo=bar and value is biz. i find it ambiguous and errorprone. please consider alternative approach.

for example one would foo as key from following and b=ar as a value

foo=b\=ar

but it parses foo=b\ as key and =ar as value

Copy link
Contributor

@StrongestNumber9 StrongestNumber9 Feb 24, 2025

Choose a reason for hiding this comment

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

Is non-greedy matching an option? Such as (?<key>.+?)=(?<value>.+) That would result foo being key and b=ar being the value

https://regex101.com/r/N9TUyg/1

Copy link
Member

Choose a reason for hiding this comment

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

it is, however it does not do escaping properly, i think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a regex expert but I think I managed to fix it. Now the capture groups allow equal signs only if they are escaped. The regex now expects only one actual equal sign which is between the key and the value. The code then unescapes the equal signs for the user before putting them into the map.

Made some new tests for checking that it is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow any key in args config

7 participants