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

Refactor '_validateURI' to use dynamic RegExp #216

Conversation

lucasrmendonca
Copy link
Contributor

Description, Motivation and Context

Refactor '_validateURI' to use dynamic RegExp

What kind of change does this PR introduce?

  • Refactoring (no new functionality, only code improvements)

Checklist:

  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • Overall test coverage is not decreased.
  • All new and existing tests passed.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@coveralls
Copy link

coveralls commented Dec 31, 2022

Coverage Status

Coverage: 98.313% (-0.003%) from 98.316% when pulling 879d0a8 on lucasrmendonca:AddDynamicRegexToValidateURI into ce96e0a on KSDaemon:dev.

}
const char = isStrictValidation ? '[0-9a-zA-Z_]' : '[^\\s.#]';
const dots = isPatternBased ? '\\.{1,2}' : '\\.';
const uriPattern = new RegExp(`^(${char}+${dots})*${char}+$`);
Copy link
Owner

Choose a reason for hiding this comment

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

Hm... I was looking at this a few times, and think that the original variant is a little easier to read/follow. Because here there are a few inline checks first, then Regexp is constructed via template string. So to figure out what flow will be — you have to look at regexp, destruct the template there, then holding that in mind try to compile in the head what values will be for each template parameter...

So at least, it is hard to construct and see the whole regexp. I don't talk about debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I see your point, my initial idea was to make the differences between each regex line easier to spot since they had a lot similarities. So by doing this it's easier to see that the char matcher and the dots matcher are the ones that are changing. But I agree the flow has been hurt.

One alternative is to add comments with examples of URIs that match each type of validation, but if you feel better keeping the current version I'm fine with that 😃

@lucasrmendonca lucasrmendonca deleted the AddDynamicRegexToValidateURI branch January 3, 2023 00:27
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