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(core): avoid attribute names being scanned as symbols. Fixes #5673 #6624

Merged
merged 6 commits into from May 22, 2024

Conversation

runeb
Copy link
Member

@runeb runeb commented May 10, 2024

In the mutator package, we scan for certain symbols, among them "true" and "false". If an attribute name is prefixed with a symbol value, the string scanning will eagerly interpret it as a symbol instead of an attribute. This patch checks that there is no more valid attribute characters immediately after the potential symbol, so that the string "trueAttribute" will not be interpreted as the symbol "true".

@runeb runeb requested a review from a team as a code owner May 10, 2024 18:27
@runeb runeb requested a review from jtpetty May 10, 2024 18:27
Copy link

vercel bot commented May 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview May 21, 2024 4:11pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2024 4:11pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2024 4:11pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 21, 2024 4:11pm

Copy link
Contributor

No changes to documentation

@runeb runeb changed the title fix(core): avoid attribute names being scanned as symbols fix(core): avoid attribute names being scanned as symbols. Fixes #5673 May 10, 2024
@runeb runeb changed the title fix(core): avoid attribute names being scanned as symbols. Fixes #5673 fix(core): avoid attribute names being scanned as symbols May 10, 2024
Copy link
Contributor

github-actions bot commented May 10, 2024

Component Testing Report Updated May 21, 2024 4:16 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 32s 11 7 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 17s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ❌ Failed (Inspect) 1m 9s 17 0 1
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 7s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 20s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 15s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 28s 12 0 0

@@ -183,6 +183,10 @@ const cases = {
},
],
},
trueOrFalseField: {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a test that fails if this name is just true or false to make sure we didn't just break something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added explicit tests for parsing symbols versus attributes/identifiers

// need to make sure we don't inadvertently treat an attribute as a
// symbol. For example, an attribute 'trueCustomerField' should not be
// scanned as the boolean symbol "true".
if (str[0].match(attributeCharMatcher)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we know what the perf hit is on looking ahead on each match?

Copy link
Member Author

@runeb runeb May 15, 2024

Choose a reason for hiding this comment

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

It would only do this extra check when it encounters a symbol match which is all attribute-valid chars, meaning "true" and "false"

bjoerge
bjoerge previously approved these changes May 16, 2024
Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

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

Nice, thanks also for the added tests :)

@runeb runeb changed the title fix(core): avoid attribute names being scanned as symbols fix(core): avoid attribute names being scanned as symbols. Fixes #5673 May 17, 2024
@runeb runeb requested a review from bjoerge May 17, 2024 19:40
@runeb
Copy link
Member Author

runeb commented May 17, 2024

Nice, thanks also for the added tests :)

merged in next and fixed a linting issue so the checks pass

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.

None yet

5 participants