libwww-perl / URI

The Perl URI module
https://metacpan.org/pod/URI
Other
41 stars 48 forks source link

fix uri_escape support for \w style character classes #112

Closed haarg closed 1 year ago

haarg commented 1 year ago

uri_escape accepts a set of characters as its second parameter. This would have some escaping done on it before being put in an eval to generate an an escaping sub.

The last release of URI attempted to do extra escaping on this character set. It tried to match the allowed forms of character classes, including a-z and [:alpha:] forms, an escaping everything else. But it didn't allow for character classes like \w. This broke several modules.

The original design of the code was written for prehistoric versions of perl that didn't support compiled regexes (qr//). This is why it needed the eval and sub generation. The supported perl versions all support qr// objects, so we can compile using them rather than eval. This means much less needs to be escaped. Specifically, only the [] characters themselves. If we allow through the POSIX class forms ([:alpha:]), escaping all others, we can still be safe but allow all existing forms to be used.

This can result in warnings when attempting to use escapes like \Q...\E, which are not valid character class escapes. These warnings are appropriate, so test for them.

Some existing tests were expecting any backslash in the input to result in backslashes being escaped. Since we are now allowing all backslash sequences through, this is inappropriate. The tests needed to be changed.

Fixes #111

codecov[bot] commented 1 year ago

Codecov Report

Base: 86.87% // Head: 86.90% // Increases project coverage by +0.03% :tada:

Coverage data is based on head (d1d97d8) compared to base (72a9be7). Patch coverage: 91.66% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #112 +/- ## ========================================== + Coverage 86.87% 86.90% +0.03% ========================================== Files 48 48 Lines 1767 1772 +5 Branches 461 461 ========================================== + Hits 1535 1540 +5 Misses 81 81 Partials 151 151 ``` | [Impacted Files](https://codecov.io/gh/libwww-perl/URI/pull/112?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libwww-perl) | Coverage Δ | | |---|---|---| | [lib/URI/Escape.pm](https://codecov.io/gh/libwww-perl/URI/pull/112/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libwww-perl#diff-bGliL1VSSS9Fc2NhcGUucG0=) | `95.00% <91.66%> (+0.71%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libwww-perl). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libwww-perl)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

oalders commented 1 year ago

Thanks @haarg! 🚀