Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix createSharedEntry(...) when using query string versioning strategy
- Loading branch information
Showing
4 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const url = require('url'); | ||
|
||
module.exports = function(filename) { | ||
const parsedFilename = new url.URL(filename, 'http://foo'); | ||
const extension = path.extname(parsedFilename.pathname); | ||
return extension ? extension.slice(1) : ''; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const getFileExtension = require('../../lib/utils/get-file-extension'); | ||
|
||
describe('get-file-extension', () => { | ||
it('returns the extension of simple filenames', () => { | ||
expect(getFileExtension('foo.js')).to.equal('js'); | ||
expect(getFileExtension('foo-bar.txt')).to.equal('txt'); | ||
expect(getFileExtension('foo.bar.baz')).to.equal('baz'); | ||
}); | ||
|
||
it('returns an empty string for files with no extension', () => { | ||
expect(getFileExtension('foo')).to.equal(''); | ||
expect(getFileExtension('foo-bar')).to.equal(''); | ||
}); | ||
|
||
it('returns the extension of a file from an absolute path', () => { | ||
expect(getFileExtension('/home/foo/bar.js')).to.equal('js'); | ||
expect(getFileExtension('C:\\home\\foo\\bar.js')).to.equal('js'); | ||
}); | ||
|
||
it('returns the extension from an URI', () => { | ||
expect(getFileExtension('http://localhost/foo.js')).to.equal('js'); | ||
expect(getFileExtension('file://localhost/foo/bar.txt')).to.equal('txt'); | ||
expect(getFileExtension('https://localhost:8080/foo.bar.baz')).to.equal('baz'); | ||
}); | ||
|
||
it('works with query strings', () => { | ||
expect(getFileExtension('http://localhost/foo.js?abcd')).to.equal('js'); | ||
expect(getFileExtension('foo.txt?bar=baz&baz=bar')).to.equal('txt'); | ||
}); | ||
}); |