-
-
Notifications
You must be signed in to change notification settings - Fork 283
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 #231 allow square brackets in path #264
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need tests
I have a problem when setting up development environment on Windows. Because the file name/dir name under Currently what I have done:
any suggestion? |
@loveky can you fix it in this PR? Just disable this test if you in window |
got it. will work on that |
src/utils/escape.js
Outdated
@@ -8,7 +8,8 @@ export default function escape(context, from) { | |||
// Handles special characters in paths | |||
const absoluteContext = path.resolve(context) | |||
.replace(/\\/, '/') | |||
.replace(/[\*|\?|\!|\(|\)|\[|\]|\{|\}]/g, (substring) => `\\${substring}`); | |||
.replace(/[\*|\?|\!|\(|\)|\{|\}]/g, (substring) => `\\${substring}`) | |||
.replace(/\[/g, '[[]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks strange. Can you describe why past solution doesn't work?
the reason why I modified escape.js is that minimatch will replace all In the updated commits, I also move the creation of special helper directory to a script. The scrip will create directories/files based the system developers working on. This should also resolve #220 |
const dir = path.dirname(file); | ||
mkdirp.sync(path.join(baseDir, dir)); | ||
fs.writeFileSync(path.join(baseDir, file), specialFiles[originFile]); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add \n
at end file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loveky just one small fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which file should I add \n
? createSpecialDirectory.js
itself? or the files created by it? 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loveky in this file 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 😃
tests/index.js
Outdated
@@ -15,6 +15,8 @@ import cacache from 'cacache'; | |||
import isGzip from 'is-gzip'; | |||
import zlib from 'zlib'; | |||
|
|||
import removeIllegalCharacterForWindows from '../scripts/removeIllegalCharacterForWindows'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be in src/utils
instead of scripts/
otherwise it won't get published.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loveky yep, move this to tests/utils
Tried a build from this PR on my windows machine with a directory using parenthesis and the assets were copied. |
The lack of new tests might lead to regressions on special character support though. |
Hi @filipesilva , the square brackets is already in the tests. Should I add more tests? any suggestion? |
I did not realize that, sorry for the confusion! |
@filipesilva can we merge this, for me LGTM, but i don't have windows near |
tests/index.js
Outdated
@@ -15,6 +15,8 @@ import cacache from 'cacache'; | |||
import isGzip from 'is-gzip'; | |||
import zlib from 'zlib'; | |||
|
|||
import removeIllegalCharacterForWindows from '../scripts/removeIllegalCharacterForWindows'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loveky yep, move this to tests/utils
@@ -984,7 +993,7 @@ describe('apply function', () => { | |||
'nested/nestedfile.txt' | |||
], | |||
patterns: [{ | |||
from: '[special?directory]' | |||
from: (path.sep === '/' ? '[special?directory]' : '[specialdirectory]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path.sep
conditionals are fairly non-obvious as to their purpose. Separate windows only tests would probably make more sense and simplify maintenance moving forward.
@evilebottnawi A Windows CI instance would probably be very useful for this plugin since windows pathing is vastly different than linux/MacOS/etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clydin we already use appveyor
for many plugins, need merge webpack-default
here, will be done in near future
tests/index.js
Outdated
@@ -1390,7 +1399,7 @@ describe('apply function', () => { | |||
'noextension' | |||
], | |||
options: { | |||
ignore: ['directory/**/*', '\\[special\\?directory\\]/**/*'] | |||
ignore: ['directory/**/*', (path.sep === '/' ? '\\[special\\?directory\\]/**/*' : '[[]specialdirectory]/**/*')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The escape sequences should be consistent and there should really be a test for both escaping techniques (where appropriate) as they are both accepted.
const path = require('path'); | ||
|
||
module.exports = function (string) { | ||
return path.sep === '/' ? string : string.replace(/[*?"<>|]/g, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If those are illegal characters on windows only then a check for windows should be used instead of path.sep
which does not guarantee windows. (process.platform === 'win32'
?)
const specialFiles = { | ||
'[special?directory]/nested/nestedfile.txt': '', | ||
'[special?directory]/(special-*file).txt': 'special', | ||
'[special?directory]/directoryfile.txt': 'new' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a test with !
in the file/path should be added to ensure that [!]
works as intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loveky yep, add test
src/utils/escape.js
Outdated
@@ -8,7 +8,7 @@ export default function escape(context, from) { | |||
// Handles special characters in paths | |||
const absoluteContext = path.resolve(context) | |||
.replace(/\\/, '/') | |||
.replace(/[\*|\?|\!|\(|\)|\[|\]|\{|\}]/g, (substring) => `\\${substring}`); | |||
.replace(/[\*|\?|\!|\(|\)|\[|\{|\}]/g, (substring) => `[${substring}]`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closing brace should probably stay for consistency (i.e., makes for a simple rule of escape all special characters).
src/utils/escape.js
Outdated
@@ -8,7 +8,7 @@ export default function escape(context, from) { | |||
// Handles special characters in paths | |||
const absoluteContext = path.resolve(context) | |||
.replace(/\\/, '/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this replacement be removed if the character class escaping method is being used?
Also, on MacOS, this r\!4
is a valid directory name.
I can say that in my windows machine the test suite in |
@filipesilva not, just this PR |
@evilebottnawi @clydin @filipesilva I have updated code and added some new tests. |
wait @filipesilva approve |
Oh sorry, didn't mean to keep you waiting! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to everyone.
fixes #231 fixes #220