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

Implement word boundary checks in regular expressions #14129

Conversation

jinjun1994
Copy link
Contributor

@jinjun1994 jinjun1994 commented Aug 4, 2023

See WebGPU use glsl bug : non-opaque uniforms outside a block - Bugs - Babylon.js

In the current implementation of regular expressions intended to match the GLSL keywords "in", "out", and "varying", it has been found that the patterns may match parts of variable names or within comments that contain these keywords, leading to inaccurate results.
Example

vec3 origin = vec3(0.0);

To improve accuracy, word boundaries (\b) have been applied around each keyword in the regular expressions. This ensures that the engine would only match complete words, not substrings within longer words or comments.

The regular expressions have been updated as follows:

const outRegex = /(flat\s)?\s*\bout\b /;
const inRegex = /(flat\s)?\s*\bin\b /;
const varyingRegex = /(flat\s)?\s*\bvarying\b/ ;

In the current implementation of regular expressions intended to match the GLSL keywords "in", "out", and "varying", it has been found that the patterns may match parts of variable names or within comments that contain these keywords, leading to inaccurate results.

To improve accuracy, word boundaries (\b) have been applied around each keyword in the regular expressions. This ensures that the engine would only match complete words, not substrings within longer words or comments.

The regular expressions have been updated as follows:
const outRegex = /(flat\s)?\s*\bout\b /;
const inRegex = /(flat\s)?\s*\bin\b /;
const varyingRegex = /(flat\s)?\s*\bvarying\b/ ;

While this improves the keyword matching accuracy, please note that particularly advanced cases like keyword usage inside comments might still not be handled perfectly. For deeper parsing needs, consider using a dedicated GLSL parser or compiler plugin.
@bjsplat
Copy link
Collaborator

bjsplat commented Aug 4, 2023

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Aug 4, 2023

remove the trailing spaces
@jinjun1994 jinjun1994 requested a review from Popov72 August 4, 2023 09:46
@Popov72
Copy link
Contributor

Popov72 commented Aug 4, 2023

Thanks!

@RaananW RaananW merged commit 44742cb into BabylonJS:master Aug 4, 2023
9 checks passed
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.

None yet

4 participants