Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

🐛 Fixed root option trailing slash issue #609

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/url/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* Root Prefix Transform.
*/

import { isString } from '../util';
import { isString, trimEnd } from '../util';

export default function (options, next) {

var url = next(options);

if (isString(options.root) && !url.match(/^(https?:)?\//)) {
url = options.root + '/' + url;
if (isString(options.root) && !/^(https?:)?\//.test(url)) {
url = trimEnd(options.root, '/') + '/' + url;
}

return url;
Expand Down
10 changes: 10 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export function trim(str) {
return str ? str.replace(/^\s*|\s*$/g, '') : '';
}

export function trimEnd(string, chars) {
if (string && chars === undefined) {
return string.replace(/\s+$/, '');
}
if (!string || !chars) {
return string;
}
return string.replace(new RegExp(`[${chars}]+$`), '');
}

export function toLower(str) {
return str ? str.toLowerCase() : '';
}
Expand Down