-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
[Ruby] Fix incorrect escaping of Ruby forward slashes #16474
Merged
wing328
merged 2 commits into
OpenAPITools:master
from
ivgiuliani:fix-ruby-forward-slash-escape
Sep 5, 2023
Merged
[Ruby] Fix incorrect escaping of Ruby forward slashes #16474
wing328
merged 2 commits into
OpenAPITools:master
from
ivgiuliani:fix-ruby-forward-slash-escape
Sep 5, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ivgiuliani
commented
Sep 1, 2023
Comment on lines
+53
to
+63
- name: alternation_with_forward_slash | ||
in: header | ||
schema: | ||
type: string | ||
pattern: '/ax$|/bx$' | ||
- name: patten_starts_ends_with_slash | ||
in: header | ||
schema: | ||
type: string | ||
pattern: '/root/' | ||
description: 'Should match only /root/ but not root' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added new test cases here rather than creating a separate file, but please let me know if there's a preference for keeping this separate
Ruby is not correctly escaping pattern sequences containing forward slashes in their definition. This commit adds tests that verify the correct behaviour of the code generator. See issue OpenAPITools#5582.
Ruby regexs are always generated as match patterns enclosed in slash characters (i.e. using the `/pattern/` syntax). Regular expressions defined in the OpenAPI declaration via the `pattern` attribute follow [ECMA 262](https://262.ecma-international.org/5.1/#sec-15.10.1) which means they already include the correct escaping of forward slashes as far as Ruby is concerned. The current Ruby codegen is incorrectly escaping all forward slashes, which ultimately causes the generated code to include additional incorrect escape sequences which cause the generated file to have an invalid syntax. This commit ports the same fix introduced in OpenAPITools#1539 for the Python codegen, as both Ruby and Python use perl-flavored regular expressions so they behave in the same way when it comes to escaping forward slashes. Fixes OpenAPITools#5582.
4d08025
to
f0773bb
Compare
@ivgiuliani thanks for the PR. I'll take a look tomorrow. |
Let's go with what you've so far. Thanks for the PR. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ruby regexs are always generated as match patterns enclosed in slash characters (i.e. using the
/pattern/
syntax). Regular expressions defined in the OpenAPI declaration via thepattern
attribute follow ECMA 262 which means they already include the correct escaping of forward slashes as far as Ruby is concerned.The current Ruby codegen is incorrectly escaping all forward slashes, which ultimately causes the generated code to include additional incorrect escape sequences which cause the generated file to have an invalid syntax.
This commit ports the same fix introduced in #1539 for the Python codegen, as both Ruby and Python use perl-flavored regular expressions so they behave in the same way when it comes to escaping forward slashes.
Fixes #5582.
cc @cliffano (2017/07) @zlx (2017/09) @autopp (2019/02)
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(7.0.1 - patch release),7.1.x
(minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)