Просмотр исходного кода

improve path-utils.normalizePath

Yuki Takei 7 лет назад
Родитель
Сommit
ff077751ed
2 измененных файлов с 8 добавлено и 0 удалено
  1. 3 0
      src/lib/util/path-utils.js
  2. 5 0
      src/test/util/path-utils.test.js

+ 3 - 0
src/lib/util/path-utils.js

@@ -66,6 +66,9 @@ function removeTrailingSlash(path) {
 
 function normalizePath(path) {
   const match = matchSlashes(path);
+  if (match == null) {
+    return '/';
+  }
   return `/${match[3]}`;
 }
 

+ 5 - 0
src/test/util/path-utils.test.js

@@ -9,6 +9,11 @@ const pathUtils = require('@commons/util/path-utils');
 describe('page-utils', () => {
 
   describe('.normalizePath', () => {
+    it('should rurn root path with empty string', done => {
+      expect(pathUtils.normalizePath('')).to.equal('/');
+      done();
+    });
+
     it('should add heading slash', done => {
       expect(pathUtils.normalizePath('hoge/fuga')).to.equal('/hoge/fuga');
       done();