-
Notifications
You must be signed in to change notification settings - Fork 559
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(smithy-client): remove capturing groups from date regex #3008
Conversation
7f570da
to
6a7d4fc
Compare
More details of the root cause for both of the issue: We found in the production build of Create-React-App, Babal will intercept the RegExp if it uses named matching. The aws-sdk-js-v3/packages/smithy-client/src/date-utils.ts Lines 40 to 42 in c244678
are transfered into something like below in uglified code:
And this code cannot match the updated regex. This issue only affects the production code that uses the mentioned Babel plugin, which is used by default in So the fix is removing the named matching from the regex. We've validated it fixes the issue in Create-React-App. |
@adamthom-amzn After digging more on the root cause of the issue, the root cause above in inexact. The original code uses RegExp literal in the const RFC3339 = /^(?<Y>\d{4})-(?<M>\d{2})-(?<D>\d{2})[tT](?<H>\d{2}):(?<m>\d{2}):(?<s>\d{2})(?:\.(?<frac>\d+))?[zZ]$/; However here, the original code used the constructor, so the mentioned Babel plugin won't fully kick in. Babel only removes the capturing name Furthermore, RegExp literals in RegExp constructor is only supported since ES 6(link). Most(with default browser list 0.2%) of the React app will transpile the source code to ES5. A more reasonable fix for it could have been using string literals instead: const RFC3339 = new RegExp("^(?<Y>\\d{4})-(?<M>\\d{2})-(?<D>\\d{2})[tT](?<H>\\d{2}):(?<m>\\d{2}):(?<s>\\d{2})(?:\\.(?<frac>\\d+))?[zZ]$"); I have verified it works. But since the current fix also works, I won't revert the change. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Issue
#2977
#2866
Description
A babel plugin is altering regexes with named capturing groups in such a way that renders them invalid.
Testing
Locally in an amplify app, and with unit tests.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.