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

Fix regexp in ruby-client #1521

Merged
merged 2 commits into from
Nov 28, 2018
Merged

Conversation

meganemura
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

(details of the change, additional tests that have been done, reference to the issue for tracking, etc)

This fixes #1520.

Assert.assertEquals(op.allParams.get(4).pattern, "/^pattern$/im");
// pattern_dont_escape_backslash '/^pattern\d{3}$/i' NOTE: the double \ is to escape \ in string but is read as single \
Assert.assertEquals(op.allParams.get(5).pattern, "/^pattern\\d{3}$/i");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meganemura I suggest we keep these tests to ensure the change won't break the previous use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see this comment
#1521 (comment)

@wing328 wing328 added this to the 3.3.4 milestone Nov 24, 2018
@wing328
Copy link
Member

wing328 commented Nov 24, 2018

cc @cliffano (2017/07) @zlx (2017/09)

// pattern_one_slash_end '^pattern$/'
Assert.assertEquals(op.allParams.get(3).pattern, "/^pattern$/");
// pattern_one_slash_near_end '^pattern$/im'
Assert.assertEquals(op.allParams.get(4).pattern, "/^pattern$/im");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 @ggershoni
This PR does not have backward compatibility for these 3 patterns in definitions.
But, it seems that those regexp patterns are not correct regular expressions.

I think we do not need to support. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to ensure that if forward slashes where not surrounding the inputted regex then they would be added to force the inputted text to be a treated as a regex literal... I wanted to prevent someone from putting in malicious code via pattern. The Mustache template doesn't surround the regex with quotes anymore.

I was thinking we could put forward slashes in the Mustache template but then we might have an ending forward slash when we didn't want one i.e. /^pattern$/i/.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meganemura I read the code in addRegularExpressionDelimiter and I like it. Thanks heaps for the refactor!

@wing328 I am happy to have those 3 tests removed. @meganemura is right, they are not correct regular expressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggershoni Thanks for reviewing 👍

@wing328 wing328 merged commit ebf67e6 into OpenAPITools:master Nov 28, 2018
@meganemura meganemura deleted the ruby-fix-regexp branch November 28, 2018 08:41
@wing328
Copy link
Member

wing328 commented Dec 4, 2018

@meganemura thanks for the PR, which has been included in the v3.3.4 release: https://twitter.com/oas_generator/status/1068772409795207168

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* Fix regexp in ruby-client

* Remove tests for unknown regexp patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ruby] Generated client has a syntax-error
3 participants