fix(optimizer): handle more chars that will be sanitized#22208
Conversation
|
The approach of aligning One concern: |
bluwy
left a comment
There was a problem hiding this comment.
I checked and I think this should invalidate the metadata hash so it's reoptimized on Vite update. Otherwise it might still refer to the old paths.
| .replaceAll('_', '__') | ||
| // replace any characters that will be replaced by sanitizeFileName | ||
| .replace(invalidUrlPathCharRE, (c) => '_' + c.charCodeAt(0).toString(16)) | ||
| .replace( | ||
| additionalFlattenIdCharRE, | ||
| (c) => '_' + c.charCodeAt(0).toString(16), | ||
| ) | ||
| .replace(replaceNestedIdRE, '__'), |
There was a problem hiding this comment.
The _2f pattern here makes it harder to read personally. I understand making it robust, but maybe we can go with a middleground:
What if we do the normal underscore replacements for the commons chars, like / and ., and then do the _2f pattern for the rest? Maybe even _2f_ so it's slightly easier to read.
Also, it'd be nice to have some more tests for the new chars.
There was a problem hiding this comment.
I've improved the logic to make the output simpler for / and .. Does this look better?
Since
$is also sanitized by Rolldown bysanitizeFileName, the filename does not contain$.#21886 fixed a similar issue for
+, but it was not a general fix. In this PR, I've rewritten theflattenIdfunction to escape any characters that will be escaped by the defaultsanitizeFileName.close #22198