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

"regex-word" rule patterns have the wrong precedence #370

Closed
scovetta opened this issue May 19, 2021 · 2 comments · Fixed by #371
Closed

"regex-word" rule patterns have the wrong precedence #370

scovetta opened this issue May 19, 2021 · 2 comments · Fixed by #371
Assignees
Labels
bug Something isn't working

Comments

@scovetta
Copy link
Member

scovetta commented May 19, 2021

Describe the bug
Example:
Take a rule like AI015600 (Data: Audio File). The raw pattern is mp2|mp3|mp4... with a type of regex-word. This translates to the regex \bmp2|mp3|mp4...\b, which isn't right -- e.g. foomp3bar matches this, since the \b's are attached to the first and last strings.

It looks like we have a bunch of this -- it might be a regression in the dev branch, but we might want to update:

https://github.com/microsoft/ApplicationInspector/blob/development/RulesEngine/Ruleset.cs#L401

from:
pattern.Pattern = string.Format(CultureInfo.InvariantCulture, @"\b{0}\b", pattern.Pattern);
to
pattern.Pattern = string.Format(CultureInfo.InvariantCulture, @"\b({0})\b", pattern.Pattern);

To Reproduce
Steps to reproduce the behavior:

  1. Download NPM/left-pad@1.3.0.
  2. Run Application Inspector (latest beta) on it.
  3. Notice the false positives, like AI015600 found in package/perf/perf.js (matching "hma" in "Benchmark").

Expected behavior
Regex-word should only match complete words (e.g. \b(THING)\b).

Screenshots
n/a

Additional context
ApplicationInspector.CLI 1.3.11-beta+69410edbd6

@scovetta scovetta added the bug Something isn't working label May 19, 2021
@gfs
Copy link
Contributor

gfs commented May 19, 2021

This is fixed in #369

gfs added a commit that referenced this issue May 19, 2021
@gfs
Copy link
Contributor

gfs commented May 19, 2021

I created a separate PR to one off fix this for 1.2, but this was already fixed in 1.3. I like your solution better than mine (splitting up the bars into separate regexes) so I've adopted that in #369 for 1.3.

#371 will fix this for 1.2.

@gfs gfs linked a pull request May 19, 2021 that will close this issue
@gfs gfs closed this as completed in #371 May 19, 2021
gfs added a commit that referenced this issue May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants