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(shouldIgnore): filename normalization should be platform sensitive #4631

Merged
merged 4 commits into from Oct 11, 2016

Conversation

rozele
Copy link
Contributor

@rozele rozele commented Oct 1, 2016

Q A
Bug fix? yes
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? yes
Tests added/pass? yes
Fixed tickets
License MIT
Doc PR

shouldIgnore normalizes the path of the filename prior to running any "only" regexes or functions. The normalization uses "slash", which has some undesirable special cases for non-ASCII characters and longer paths. Changing the normalization behavior to always replace path separators.

There is no real need to add additional tests, because the tests are not run in an environment where path.sep !== '/' anyway.

shouldIgnore normalizes the path of the filename prior to running any "only" regexes or functions. The normalization uses "slash", which has some undesirable special cases for non-ASCII characters and longer paths. Changing the normalization behavior to always replace path separators.

There is no real need to add additional tests, because the tests are not run in an environment where path.sep !== '/'.
@codecov-io
Copy link

codecov-io commented Oct 3, 2016

Current coverage is 88.78% (diff: 100%)

Merging #4631 into master will increase coverage by 0.03%

@@             master      #4631   diff @@
==========================================
  Files           195        195          
  Lines         13773      13822    +49   
  Methods        1425       1434     +9   
  Messages          0          0          
  Branches       3171       3196    +25   
==========================================
+ Hits          12223      12272    +49   
  Misses         1550       1550          
  Partials          0          0          

Powered by Codecov. Last update 0e02a18...3a6c8f6

@rozele
Copy link
Contributor Author

rozele commented Oct 5, 2016

Any feedback on this?

@hzoo
Copy link
Member

hzoo commented Oct 5, 2016

Don't know much about what it's doing there - would there be other places we want to do this?

Also this would be removing filename = slash(filename); in the default case?

@rozele
Copy link
Contributor Author

rozele commented Oct 5, 2016

@hzoo there may be other cases. In this specific case it has an impact on the babel register behavior. If I register babel to transform paths matching /foo\/bar/ then, I presume the use of slash is to ensure that the regex also matches foo\bar for Windows. Unfortunately, I don't know enough about the expected behavior of babel in general, and there are a few other uses I didn't investigate. All I know is that there are a number of issues on StackOverflow and a few GitHub issues on facebook/react-native (e.g., facebook/react-native#10033 and facebook/react-native#8899) that are sourced from this here.

@danez danez added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Oct 11, 2016
Copy link
Member

@danez danez left a comment

Choose a reason for hiding this comment

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

This looks overall valid to me, as we do not care about long paths and non-ascii characters in the filename, as everything we want to do here is simply doing string comparison with the strings and not use any path functionality.

@@ -116,7 +116,9 @@ export function shouldIgnore(
ignore: Array<RegExp | Function> = [],
only?: Array<RegExp | Function>,
): boolean {
filename = slash(filename);
if (path.sep !== "/") {
Copy link
Member

@danez danez Oct 11, 2016

Choose a reason for hiding this comment

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

We probably can safely remove this check, as slash() is also always doing the replacement, not matter what path.sep is set to.
https://github.com/sindresorhus/slash/blob/master/index.js

@rozele
Copy link
Contributor Author

rozele commented Oct 11, 2016

Thanks @danez, removed the conditional as you suggested.

@hzoo hzoo merged commit c2387f0 into babel:master Oct 11, 2016
panagosg7 pushed a commit to panagosg7/babel that referenced this pull request Jan 17, 2017
babel#4631)

* fix(shouldIgnore): filename normalization should be platform sensitive

shouldIgnore normalizes the path of the filename prior to running any "only" regexes or functions. The normalization uses "slash", which has some undesirable special cases for non-ASCII characters and longer paths. Changing the normalization behavior to always replace path separators.

There is no real need to add additional tests, because the tests are not run in an environment where path.sep !== '/'.

* Minor style fix to use double quotes.

* Remove conditional for regex replace to keep consistent behavior.

* whitespace [skip ci]
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants