Skip to content

Commit a33fb05

Browse files
committed
Merge pull request bower#1076 from neoziro/fix-cache-directory-reading
Fix reading versions from cache directory.
2 parents de52fa5 + 3dbddfb commit a33fb05

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/core/ResolveCache.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ResolveCache.prototype.retrieve = function (source, target) {
7676
}
7777

7878
// Resolve with canonical dir and package meta
79-
canonicalDir = path.join(dir, version);
79+
canonicalDir = path.join(dir, encodeURIComponent(version));
8080
return that._readPkgMeta(canonicalDir)
8181
.then(function (pkgMeta) {
8282
return [canonicalDir, pkgMeta];
@@ -346,6 +346,7 @@ ResolveCache.prototype._getVersions = function (sourceId) {
346346
.then(function (versions) {
347347
// Sort and cache in memory
348348
that._sortVersions(versions);
349+
versions = versions.map(decodeURIComponent);
349350
that._cache.set(sourceId, versions);
350351
return [versions, false];
351352
}, function (err) {

test/core/resolveCache.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ describe('ResolveCache', function () {
529529
var sourceId = md5(source);
530530
var sourceDir = path.join(cacheDir, sourceId);
531531
var json = { name: 'foo' };
532+
var encoded;
532533

533534
// Create some versions
534535
fs.mkdirSync(sourceDir);
@@ -538,22 +539,25 @@ describe('ResolveCache', function () {
538539
fs.writeFileSync(path.join(sourceDir, '0.1.0', '.bower.json'), JSON.stringify(json, null, ' '));
539540

540541
json.version = '0.1.0+build.4';
541-
fs.mkdirSync(path.join(sourceDir, '0.1.0+build.4'));
542-
fs.writeFileSync(path.join(sourceDir, '0.1.0+build.4', '.bower.json'), JSON.stringify(json, null, ' '));
542+
encoded = encodeURIComponent('0.1.0+build.4');
543+
fs.mkdirSync(path.join(sourceDir, encoded));
544+
fs.writeFileSync(path.join(sourceDir, encoded, '.bower.json'), JSON.stringify(json, null, ' '));
543545

544546
json.version = '0.1.0+build.5';
545-
fs.mkdirSync(path.join(sourceDir, '0.1.0+build.5'));
546-
fs.writeFileSync(path.join(sourceDir, '0.1.0+build.5', '.bower.json'), JSON.stringify(json, null, ' '));
547+
encoded = encodeURIComponent('0.1.0+build.5');
548+
fs.mkdirSync(path.join(sourceDir, encoded));
549+
fs.writeFileSync(path.join(sourceDir, encoded, '.bower.json'), JSON.stringify(json, null, ' '));
547550

548551
json.version = '0.1.0+build.6';
549-
fs.mkdirSync(path.join(sourceDir, '0.1.0+build.6'));
550-
fs.writeFileSync(path.join(sourceDir, '0.1.0+build.6', '.bower.json'), JSON.stringify(json, null, ' '));
552+
encoded = encodeURIComponent('0.1.0+build.6');
553+
fs.mkdirSync(path.join(sourceDir, encoded));
554+
fs.writeFileSync(path.join(sourceDir, encoded, '.bower.json'), JSON.stringify(json, null, ' '));
551555

552556
resolveCache.retrieve(source, '0.1.0+build.5')
553557
.spread(function (canonicalDir, pkgMeta) {
554558
expect(pkgMeta).to.be.an('object');
555559
expect(pkgMeta.version).to.equal('0.1.0+build.5');
556-
expect(canonicalDir).to.equal(path.join(sourceDir, '0.1.0+build.5'));
560+
expect(canonicalDir).to.equal(path.join(sourceDir, encodeURIComponent('0.1.0+build.5')));
557561

558562
next();
559563
})

0 commit comments

Comments
 (0)