-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Prevent stripping of outer replaced characters. #38
Conversation
filenamify.js
Outdated
|
||
// Doesn't make sense to have longer filenames | ||
const MAX_FILENAME_LENGTH = 100; | ||
|
||
const reRepeatedReservedChars = /([<>:"/\\|?*\u0000-\u001F]){2,}/g; // eslint-disable-line no-control-regex |
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.
You did not fully address the feedback in #12 (comment)
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.
I didn't move it because i saw that reControlChars
is also a g
regex, and it's outside filenamify()
. Should I move that too?
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.
Yes
filenamify.js
Outdated
@@ -58,3 +58,5 @@ export default function filenamify(string, options = {}) { | |||
|
|||
return string; | |||
} | |||
|
|||
const trimRepeatedReservedChars = string => string.replace(reRepeatedReservedChars, '$1'); |
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.
const trimRepeatedReservedChars = string => string.replace(reRepeatedReservedChars, '$1'); | |
const trimRepeatedReservedCharacters = string => string.replace(reRepeatedReservedCharacters, '$1'); |
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.
I'm thinking about completely removing const trimRepeatedReservedChars
, given that after moving the regex inside filenamify()
, calling string.replace(...)
inside the if statement would be the easiest way to do it.
Fixes #11. Just like #12, "now we trim repeat and outer reserved chars before doing a global replace with the replacement char, to preserve instances of that char present in the original string".
The only difference is that I think we should maintain as much of the original string as possible, so we don't strip outer reserved characters, we only replace them with the replacement string.