utsushiiro 5 лет назад
Родитель
Сommit
36fec485b1

+ 5 - 1
packages/growi-commons/src/test/util/path-utils.test.js

@@ -5,10 +5,14 @@ const pathUtils = require('@src/util/path-utils');
 
 
 describe('page-utils', () => {
 describe('page-utils', () => {
   describe('.normalizePath', () => {
   describe('.normalizePath', () => {
-    test('should rurn root path with empty string', () => {
+    test('should return root path with empty string', () => {
       expect(pathUtils.normalizePath('')).toBe('/');
       expect(pathUtils.normalizePath('')).toBe('/');
     });
     });
 
 
+    test('should return the root page as is', () => {
+      expect(pathUtils.normalizePath('/')).toBe('/');
+    });
+
     test('should add heading slash', () => {
     test('should add heading slash', () => {
       expect(pathUtils.normalizePath('hoge/fuga')).toBe('/hoge/fuga');
       expect(pathUtils.normalizePath('hoge/fuga')).toBe('/hoge/fuga');
     });
     });

+ 4 - 0
packages/growi-commons/src/util/path-utils.js

@@ -90,6 +90,10 @@ function removeTrailingSlash(path) {
  * @memberof pathUtils
  * @memberof pathUtils
  */
  */
 function normalizePath(path) {
 function normalizePath(path) {
+  if (path === '' || path === '/') {
+    return '/';
+  }
+
   const match = matchSlashes(path);
   const match = matchSlashes(path);
   if (match == null) {
   if (match == null) {
     return '/';
     return '/';