Skip to content

Commit c3bcab0

Browse files
ming-codessamselikoff
authored andcommitted
Fix a double slash in url that causes history corruption (#332)
1 parent 5de0d85 commit c3bcab0

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

lib/deploy/plugin.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,18 @@ module.exports = class AddonDocsDeployPlugin {
155155
let addonDocsRootURL = rootURL === '' ? '/' : `/${rootURL}/`;
156156
let contents = fs.readFileSync(indexPath, 'utf-8');
157157
let encodedVersion = encodeURIComponent(JSON.stringify(deployVersion));
158-
let updated = contents.replace(/\/?ADDON_DOCS_ROOT_URL\/?/g, addonDocsRootURL)
159-
.replace(/%22ADDON_DOCS_DEPLOY_VERSION%22/g, encodedVersion);
158+
let updated = this._macroReplaceIndexContent(contents, addonDocsRootURL, encodedVersion);
160159

161160
fs.writeFileSync(indexPath, updated);
162161
}
163162

163+
_macroReplaceIndexContent(contents, addonDocsRootURL, encodedVersion) {
164+
return contents
165+
.replace('%2FADDON_DOCS_ROOT_URL%2F', encodeURIComponent(addonDocsRootURL))
166+
.replace(/\/?ADDON_DOCS_ROOT_URL\/?/g, addonDocsRootURL)
167+
.replace(/%22ADDON_DOCS_DEPLOY_VERSION%22/g, encodedVersion);
168+
}
169+
164170
_currentDeployVersion() {
165171
let curpath = path.join('versions', this._getVersionPath());
166172
let name = this.userConfig.getVersionName();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
const QUnit = require('qunit');
4+
const AddonDocsDeployPlugin = require('../../../lib/deploy/plugin');
5+
6+
const qModule = QUnit.module;
7+
const test = QUnit.test;
8+
9+
qModule('`deploy` | plugin test', hooks => {
10+
hooks.beforeEach(function() {
11+
this.pluginInstance = new AddonDocsDeployPlugin();
12+
});
13+
14+
test('_macroReplaceIndexContent', function(assert) {
15+
const contents = `
16+
<!DOCTYPE html>
17+
<html>
18+
<head>
19+
<meta name="dummy/config/environment" content="%7B%22rootURL%22%3A%22%2FADDON_DOCS_ROOT_URL%2F%22%7D" />
20+
</head>
21+
<body>
22+
<script src="/ADDON_DOCS_ROOT_URL/assets/vendor.js"></script>
23+
<script src="/ADDON_DOCS_ROOT_URL/assets/dummy.js"></script>
24+
</body>
25+
</html>
26+
`;
27+
const encodedVersion = encodeURIComponent(JSON.stringify({
28+
path: 'versions/master',
29+
name: 'master',
30+
sha: 'eef3',
31+
tag: null,
32+
key: 'master'
33+
}));
34+
const addonDocsRootURL = '/my-addon/versions/master/'
35+
const actual = this.pluginInstance._macroReplaceIndexContent(contents, addonDocsRootURL, encodedVersion);
36+
const expected = `
37+
<!DOCTYPE html>
38+
<html>
39+
<head>
40+
<meta name="dummy/config/environment" content="%7B%22rootURL%22%3A%22%2Fmy-addon%2Fversions%2Fmaster%2F%22%7D" />
41+
</head>
42+
<body>
43+
<script src="/my-addon/versions/master/assets/vendor.js"></script>
44+
<script src="/my-addon/versions/master/assets/dummy.js"></script>
45+
</body>
46+
</html>
47+
`;
48+
49+
assert.equal(actual, expected);
50+
});
51+
});

0 commit comments

Comments
 (0)