When looking for common suffixes, strip the common prefix (if any) from
the items, so that the method doesn't fail when they overlap.
This commit is contained in:
Iván Zaera Avellón 2020-12-22 12:29:08 +01:00
parent eb58387a39
commit 39adecf568
No known key found for this signature in database
GPG Key ID: DDF9E63E2A9D2A80
2 changed files with 15 additions and 1 deletions

View File

@ -134,7 +134,9 @@ const itemsToRegexp = itemsArr => {
// special case for 2 items with common prefix/suffix
if (finishedItems.length === 0 && items.size === 2) {
const prefix = getCommonPrefix(itemsArr);
const suffix = getCommonSuffix(itemsArr);
const suffix = getCommonSuffix(
itemsArr.map(item => item.substring(prefix.length))
);
if (prefix.length > 0 || suffix.length > 0) {
return `${quoteMeta(prefix)}${itemsToRegexp(
itemsArr.map(i => i.slice(prefix.length, -suffix.length || undefined))

View File

@ -77,4 +77,16 @@ describe("itemsToRegexp", () => {
`(\\.\\/path\\/to\\/(directory\\/with\\/(file\\.(js(|on)|css)|module\\.css)|file\\.(|m)js|other\\-file\\.js)|webpack\\/runtime\\/module)`
)
);
expectCompiled(
"prefix and suffix overlap",
[
"webpack_sharing_consume_default_react_react",
"webpack_sharing_consume_default_classnames_classnames-webpack_sharing_consume_default_react_react"
],
e =>
e.toMatchInlineSnapshot(
`webpack_sharing_consume_default_(|classnames_classnames\\-webpack_sharing_consume_default_)react_react`
)
);
});