validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Disallowing periods in slugs (Response to issue#2383)

Open alinaghale88 opened this issue 1 year ago • 6 comments

I have updated the regular expression pattern in isSlug.js to disallow periods for strings of type slug. I have also ensured that the modification made does not impact all the correct conditions the existing pattern supports at present.

test-results

Checklist

  • [ ] PR contains only changes related; no stray files, etc.
  • [ ] README updated (where applicable)
  • [ ] Tests written (where applicable)
  • [ ] References provided in PR (where applicable)

alinaghale88 avatar Mar 31 '24 21:03 alinaghale88

Just fyi;

This is the basis of the validator: https://gist.github.com/hagemann/382adfc57adbd5af078dc93feef01fe1

In my opinion any changes to isSlug should still conform to that gist.

I'll check later if that's the case. In the meantime; don't forget to add additional tests.

WikiRik avatar Mar 31 '24 21:03 WikiRik

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (4197b86) to head (5e19e96). Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2385   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          107       107           
  Lines         2449      2449           
  Branches       619       619           
=========================================
  Hits          2449      2449           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Apr 01 '24 08:04 codecov[bot]

@WikiRik I have added a new invalid test case and made further changes to ensure that the regular expression complies with all the valid and invalid test cases. Please review and provide your feedback.

alinaghale88 avatar Apr 01 '24 08:04 alinaghale88

Just fyi;

This is the basis of the validator: https://gist.github.com/hagemann/382adfc57adbd5af078dc93feef01fe1

In my opinion any changes to isSlug should still conform to that gist.

I'll check later if that's the case. In the meantime; don't forget to add additional tests.

Just fyi;

This is the basis of the validator: https://gist.github.com/hagemann/382adfc57adbd5af078dc93feef01fe1

In my opinion any changes to isSlug should still conform to that gist.

I'll check later if that's the case. In the meantime; don't forget to add additional tests.

@WikiRik The reference you provided seems to be changing any string that cannot be considered a slug to an actual definition of a slug. But the isSlug function's role is to validate whether or not a provided string is of type slug.

alinaghale88 avatar Apr 04 '24 02:04 alinaghale88

@alinaghale88 As mentioned here, the original regex effectively required at least 3 characters, which your revision doesn't seem to do when I tested it. Not sure if it's technically required, but just something I thought I'd mention. I use the isLength validator for my use case anyway to catch those. This change otherwise fixes my issue with special characters passing.

jfaMan avatar Apr 17 '24 06:04 jfaMan

Just fyi; This is the basis of the validator: https://gist.github.com/hagemann/382adfc57adbd5af078dc93feef01fe1 In my opinion any changes to isSlug should still conform to that gist. I'll check later if that's the case. In the meantime; don't forget to add additional tests.

Just fyi; This is the basis of the validator: https://gist.github.com/hagemann/382adfc57adbd5af078dc93feef01fe1 In my opinion any changes to isSlug should still conform to that gist. I'll check later if that's the case. In the meantime; don't forget to add additional tests.

@WikiRik The reference you provided seems to be changing any string that cannot be considered a slug to an actual definition of a slug. But the isSlug function's role is to validate whether or not a provided string is of type slug.

I believe he means in the sense that any characters Slugify retains when it 'slugifies' a string are considered valid characters in a slug, and isSlug uses this as the basis of how it validates slugs.

jfaMan avatar Apr 26 '24 04:04 jfaMan