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

Allow all characters (except /) when sanitazing #59

Merged
merged 1 commit into from
Mar 14, 2021
Merged

Conversation

K1-K1
Copy link
Contributor

@K1-K1 K1-K1 commented Jan 14, 2021

No description provided.

@bjesus
Copy link

bjesus commented Jan 16, 2021

I've been using the roles from https://github.com/parshap/node-sanitize-filename to replace some more unsafe characters, so more like this:

var illegalRe = /[\/\?<>\\:\*\|"]/g;
var controlRe = /[\x00-\x1f\x80-\x9f]/g;
var reservedRe = /^\.+$/;
var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
var windowsTrailingRe = /[\. ]+$/;

function sanitize(input, replacement) {
  if (typeof input !== 'string') {
    throw new Error('Input must be string');
  }
return input
    .replace(illegalRe, replacement)
    .replace(controlRe, replacement)
    .replace(reservedRe, replacement)
    .replace(windowsReservedRe, replacement)
    .replace(windowsTrailingRe, replacement);
}

@osnr osnr merged commit 49fea2b into osnr:master Mar 14, 2021
@osnr
Copy link
Owner

osnr commented Mar 14, 2021

Thanks to both of you! I've decided to still replace spaces but have allowed all the other characters, I think: 922e2bb#diff-bdb5cae59928803bd7b94e819be96e2f3f8dc6e3d15beae20645dec6a188cdc4R38

open to suggestions if there's a compelling use case for keeping spaces. (I also thought about getting rid of the tab ID suffix, but have decided against that for now; it adds some complexity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants