mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Merge pull request #6430 from halfdan/6428-add-trailing
Add trailing slashes on relative URL unless [.?#]
This commit is contained in:
commit
e0239c44aa
2 changed files with 90 additions and 4 deletions
|
@ -137,6 +137,10 @@ export default TextField.extend({
|
||||||
if (!url.match(/^\//)) {
|
if (!url.match(/^\//)) {
|
||||||
url = `/${url}`;
|
url = `/${url}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!url.match(/\/$/) && !url.match(/[\.#\?]/)) {
|
||||||
|
url = `${url}/`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sendAction('change', url);
|
this.sendAction('change', url);
|
||||||
|
|
|
@ -315,9 +315,9 @@ describeComponent(
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
testUrl('about');
|
testUrl('about/');
|
||||||
testUrl('about#contact');
|
testUrl('about#contact');
|
||||||
testUrl('test/nested');
|
testUrl('test/nested/');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles links to subdomains of blog domain', function () {
|
it('handles links to subdomains of blog domain', function () {
|
||||||
|
@ -341,6 +341,88 @@ describeComponent(
|
||||||
expect($input.val()).to.equal(expectedUrl);
|
expect($input.val()).to.equal(expectedUrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('adds trailing slash to relative URL', function () {
|
||||||
|
let expectedUrl = '';
|
||||||
|
|
||||||
|
this.on('updateUrl', (url) => {
|
||||||
|
expect(url).to.equal(expectedUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.render(hbs `
|
||||||
|
{{gh-navitem-url-input baseUrl=baseUrl url=url last=isLast change="updateUrl"}}
|
||||||
|
`);
|
||||||
|
let $input = this.$('input');
|
||||||
|
|
||||||
|
let testUrl = (url) => {
|
||||||
|
expectedUrl = `/${url}/`;
|
||||||
|
run(() => {
|
||||||
|
$input.val(`${currentUrl}${url}`).trigger('input');
|
||||||
|
});
|
||||||
|
run(() => {
|
||||||
|
$input.trigger('blur');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
testUrl('about');
|
||||||
|
testUrl('test/nested');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not add trailing slash on relative URL with [.?#]', function () {
|
||||||
|
let expectedUrl = '';
|
||||||
|
|
||||||
|
this.on('updateUrl', (url) => {
|
||||||
|
expect(url).to.equal(expectedUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.render(hbs `
|
||||||
|
{{gh-navitem-url-input baseUrl=baseUrl url=url last=isLast change="updateUrl"}}
|
||||||
|
`);
|
||||||
|
let $input = this.$('input');
|
||||||
|
|
||||||
|
let testUrl = (url) => {
|
||||||
|
expectedUrl = `/${url}`;
|
||||||
|
run(() => {
|
||||||
|
$input.val(`${currentUrl}${url}`).trigger('input');
|
||||||
|
});
|
||||||
|
run(() => {
|
||||||
|
$input.trigger('blur');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
testUrl('about#contact');
|
||||||
|
testUrl('test/nested.svg');
|
||||||
|
testUrl('test?gho=sties');
|
||||||
|
testUrl('test/nested?sli=mer');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not add trailing slash on non-relative URLs', function () {
|
||||||
|
let expectedUrl = '';
|
||||||
|
|
||||||
|
this.on('updateUrl', (url) => {
|
||||||
|
expect(url).to.equal(expectedUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.render(hbs `
|
||||||
|
{{gh-navitem-url-input baseUrl=baseUrl url=url last=isLast change="updateUrl"}}
|
||||||
|
`);
|
||||||
|
let $input = this.$('input');
|
||||||
|
|
||||||
|
let testUrl = (url) => {
|
||||||
|
expectedUrl = `/${url}`;
|
||||||
|
run(() => {
|
||||||
|
$input.val(`${currentUrl}${url}`).trigger('input');
|
||||||
|
});
|
||||||
|
run(() => {
|
||||||
|
$input.trigger('blur');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
testUrl('http://woo.ff/test');
|
||||||
|
testUrl('http://me.ow:2342/nested/test');
|
||||||
|
testUrl('https://wro.om/car#race');
|
||||||
|
testUrl('https://kabo.om/explosion?really=now');
|
||||||
|
});
|
||||||
|
|
||||||
describe('with sub-folder baseUrl', function () {
|
describe('with sub-folder baseUrl', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.set('baseUrl', `${currentUrl}blog/`);
|
this.set('baseUrl', `${currentUrl}blog/`);
|
||||||
|
@ -368,9 +450,9 @@ describeComponent(
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
testUrl('/about');
|
testUrl('/about/');
|
||||||
testUrl('/about#contact');
|
testUrl('/about#contact');
|
||||||
testUrl('/test/nested');
|
testUrl('/test/nested/');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles URLs relative to base host', function () {
|
it('handles URLs relative to base host', function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue