Sfoglia il codice sorgente

Fix regex matching for mime type in AssetImporter.

master
Palash Bansal 1 anno fa
parent
commit
c1788c4d70
Nessun account collegato all'indirizzo email del committer
1 ha cambiato i file con 11 aggiunte e 2 eliminazioni
  1. 11
    2
      src/assetmanager/AssetImporter.ts

+ 11
- 2
src/assetmanager/AssetImporter.ts Vedi File

@@ -587,11 +587,11 @@ export class AssetImporter extends EventDispatcher<IAssetImporterEventMap> imple
const loader = importer.ctor(this)
if (!loader) return undefined
importer.ext.forEach(iext => {
const regex = new RegExp(iext.startsWith('data:') ? '^' + iext + '\\/' : '\\.' + iext + '$', 'i')
const regex = new RegExp(iext.startsWith('data:') ? '^' + escapeRegExp(iext) + '[\\/\\+\\:\\,\\;]' : '\\.' + iext + '$', 'i')
this._loadingManager.addHandler(regex, loader)
})
importer.mime?.forEach(imime => {
const regex = new RegExp('^data:' + imime + '$', 'i')
const regex = new RegExp('^data:' + escapeRegExp(imime) + '[\\/\\+\\:\\,\\;]', 'i')
this._loadingManager.addHandler(regex, loader)
})
this._loaderCache.push({loader, ext: importer.ext, mime: importer.mime})
@@ -644,3 +644,12 @@ export class AssetImporter extends EventDispatcher<IAssetImporterEventMap> imple


}

function escapeRegExp(str: string) {
// @ts-expect-error new browser feature
return RegExp.escape ? RegExp.escape(str) :
str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
}
// function escapeReplacement(str: string) {
// return str.replace(/\$/g, '$$$$')
// }

Loading…
Annulla
Salva