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

Forward slashes are ignored when specifying string pattern #121

Closed
svile opened this issue Apr 27, 2021 · 3 comments
Closed

Forward slashes are ignored when specifying string pattern #121

svile opened this issue Apr 27, 2021 · 3 comments

Comments

@svile
Copy link
Contributor

svile commented Apr 27, 2021

🐛 Bug Report

It seems that in attempts to auto escape the regex for json compatibility the library strips out (or ignores) escaped /

To Reproduce

Steps to reproduce the behavior:

import S from 'fluent-json-schema';

const cronlike = S.string().pattern(
  /^((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*)\s?){5,6})$/,
);
console.log(cronlike.valueOf());

const cronlikeRegex = RegExp(
  /^((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*)\s?){5,6})$/,
);
console.log(cronlikeRegex);

Expected behavior

Forward slashes should also be escaped.

{
  '$schema': 'http://json-schema.org/draft-07/schema#',
  type: 'string',
  pattern: '^((((\\d+,)+\\d+|(\\d+(\\|-)\\d+)|\\d+|\\*)\\s?){5,6})$/'
}
/^((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*)\s?){5,6})$/

Your Environment

  • node version: v14.16.1
  • fluent-json-schema: 2.0.4
  • os: Mac
@aboutlo
Copy link
Collaborator

aboutlo commented Apr 27, 2021

Thank you @svile to report this.

Would you like to open a PR to fix it?
You can add the test case here: https://github.com/fastify/fluent-json-schema/blob/master/src/StringSchema.test.js#L97

@svile
Copy link
Contributor Author

svile commented Apr 27, 2021

Actually, looks like I'll have some spare time today, so I'll take it.

aboutlo pushed a commit that referenced this issue May 3, 2021
@aboutlo
Copy link
Collaborator

aboutlo commented May 8, 2021

resolved by #122

@aboutlo aboutlo closed this as completed May 8, 2021
This issue was closed.
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

No branches or pull requests

2 participants