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

Add warning for pattern traits missing ^ or $ anchors #1141

Merged
merged 1 commit into from
Mar 23, 2022

Conversation

gosar
Copy link
Contributor

@gosar gosar commented Mar 18, 2022

The pattern trait does not implicitly add a leading ^ or trailing $ to
match an entire string. If customer thinks the anchors are implicitly
added they may allow more values than expected. This WARNING will help
customers identify if they unintentionally forgot the anchors.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@gosar gosar force-pushed the pattern-anchor branch 3 times, most recently from 25766d2 to 3dd2706 Compare March 21, 2022 19:50
@gosar gosar marked this pull request as ready for review March 22, 2022 19:55
@gosar gosar requested a review from a team as a code owner March 22, 2022 19:55
@gosar gosar requested a review from mtdowling March 22, 2022 19:55
Copy link
Member

@mtdowling mtdowling left a comment

Choose a reason for hiding this comment

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

It might be nice to elaborate on the warning more with why they should anchor expressions. For example:

[WARNING] ns.foo#Structure$WithoutAnchorsMember: A pattern trait is applied without a leading '^' and trailing '$', meaning only part of the string must match the regular expression. Explicitly anchoring regular expressions is preferable because it is more restrictive by default and does not require modelers to understand that Smithy patterns are not automatically anchored. | PatternTrait

The pattern trait does not implicitly add a leading ^ or trailing $ to
match an entire string. If customer thinks the anchors are implicitly
added they may allow more values than expected. This WARNING will help
customers identify if they unintentionally forgot the anchors.
@gosar gosar merged commit fa8e6c0 into smithy-lang:main Mar 23, 2022
@gosar gosar deleted the pattern-anchor branch March 24, 2022 01:34
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 this pull request may close these issues.

3 participants