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

Bug: Unescaped slash throws error, when pattern contains slash #649

Closed
a-r-m-i-n opened this issue Jan 1, 2021 · 6 comments · Fixed by #650
Closed

Bug: Unescaped slash throws error, when pattern contains slash #649

a-r-m-i-n opened this issue Jan 1, 2021 · 6 comments · Fixed by #650

Comments

@a-r-m-i-n
Copy link
Contributor

a-r-m-i-n commented Jan 1, 2021

Here you don't escape slashes in expression: https://github.com/justinrainbow/json-schema/blob/fa4d2d3c1e40a222ded125b679891086c9a6c7d6/src/JsonSchema/Constraints/FormatConstraint.php#L200

Here you do: https://github.com/justinrainbow/json-schema/blob/fa4d2d3c1e40a222ded125b679891086c9a6c7d6/src/JsonSchema/Constraints/StringConstraint.php#L43

The first check should do the same here.

Thanks for this great lib! And a happy new year! 🥳

@erayd
Copy link
Contributor

erayd commented Jan 2, 2021

Thanks for reporting this. A PR that fixes it would be very welcome 🙂.

@ktomk
Copy link
Contributor

ktomk commented Jan 5, 2021

would you consider to file a PR on this? @a-r-m-i-n

@ktomk
Copy link
Contributor

ktomk commented Jan 5, 2021

Just asking, as I may also pick a take on it. For that I would be also interested in the "throws error" details, specifically how to provoke an error and what message of that error mentioned is. /cc @a-r-m-i-n

The str_replace looks fishy to me as preg_match is in use. Me thinks better of preg_quote for that.

@a-r-m-i-n
Copy link
Contributor Author

Here we go. I just copied the preg_match from the second place. If you want to replace the used function, feel free. I think this will at least solve the issue I currently have, when I try to use Composer's JSON schema. The "name" property there, got a check pattern for "abc/def", including the unescaped / which is also used as delimiter before.

@erayd
Copy link
Contributor

erayd commented Jan 7, 2021

The str_replace looks fishy to me as preg_match is in use. Me thinks better of preg_quote for that.

That method uses preg_match to check whether $regex is a valid regular expression, by attempting to compile it and checking for an error condition. It does not use a regular expression to validate a string. Using preg_quote would defeat the entire purpose of the validateRegex method.

@erayd erayd closed this as completed in #650 Jan 8, 2021
@ktomk
Copy link
Contributor

ktomk commented Jan 8, 2021

Thanks!

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 a pull request may close this issue.

3 participants