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

import { pathUtils } from 'growi-commons'

Yuki Takei 7 лет назад
Родитель
Сommit
4eaa436e36

+ 1 - 1
package.json

@@ -88,7 +88,7 @@
     "express-webpack-assets": "^0.1.0",
     "googleapis": "^39.1.0",
     "graceful-fs": "^4.1.11",
-    "growi-commons": "^3.0.0",
+    "growi-commons": "^3.1.0",
     "helmet": "^3.13.0",
     "i18next": "^15.0.9",
     "i18next-express-middleware": "^1.4.1",

+ 2 - 1
src/client/js/components/PagePathAutoComplete.jsx

@@ -1,7 +1,8 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 
-import * as pathUtils from '@commons/util/path-utils';
+import { pathUtils } from 'growi-commons';
+
 import SearchTypeahead from './SearchTypeahead';
 
 export default class PagePathAutoComplete extends React.Component {

+ 2 - 1
src/client/js/legacy/crowi.js

@@ -6,7 +6,8 @@ import ReactDOM from 'react-dom';
 
 import { debounce } from 'throttle-debounce';
 
-import * as pathUtils from '@commons/util/path-utils';
+import { pathUtils } from 'growi-commons';
+
 import GrowiRenderer from '../util/GrowiRenderer';
 import RevisionLoader from '../components/Page/RevisionLoader';
 

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

@@ -1,83 +0,0 @@
-
-function encodePagePath(path) {
-  const paths = path.split('/');
-  paths.forEach((item, index) => {
-    paths[index] = encodeURIComponent(item);
-  });
-  return paths.join('/');
-}
-
-function encodePagesPath(pages) {
-  pages.forEach((page) => {
-    if (!page.path) {
-      return;
-    }
-    page.path = encodePagePath(page.path);
-  });
-  return pages;
-}
-
-function matchSlashes(path) {
-  // https://regex101.com/r/Z21fEd/5
-  return path.match(/^((\/+)?(.+?))(\/+)?$/);
-}
-
-function hasHeadingSlash(path) {
-  const match = matchSlashes(path);
-  return (match[2] != null);
-}
-
-function hasTrailingSlash(path) {
-  const match = matchSlashes(path);
-  return (match[4] != null);
-}
-
-function addHeadingSlash(path) {
-  if (path === '/') {
-    return path;
-  }
-
-  if (!hasHeadingSlash(path)) {
-    return `/${path}`;
-  }
-  return path;
-}
-
-function addTrailingSlash(path) {
-  if (path === '/') {
-    return path;
-  }
-
-  if (!hasTrailingSlash(path)) {
-    return `${path}/`;
-  }
-  return path;
-}
-
-function removeTrailingSlash(path) {
-  if (path === '/') {
-    return path;
-  }
-
-  const match = matchSlashes(path);
-  return match[1];
-}
-
-function normalizePath(path) {
-  const match = matchSlashes(path);
-  if (match == null) {
-    return '/';
-  }
-  return `/${match[3]}`;
-}
-
-module.exports = {
-  encodePagePath,
-  encodePagesPath,
-  hasHeadingSlash,
-  hasTrailingSlash,
-  addHeadingSlash,
-  addTrailingSlash,
-  removeTrailingSlash,
-  normalizePath,
-};

+ 1 - 1
src/server/routes/page.js

@@ -2,7 +2,7 @@
 module.exports = function(crowi, app) {
   const debug = require('debug')('growi:routes:page');
   const logger = require('@alias/logger')('growi:routes:page');
-  const pathUtils = require('@commons/util/path-utils');
+  const pathUtils = require('growi-commons').pathUtils;
   const Page = crowi.model('Page');
   const User = crowi.model('User');
   const Config = crowi.model('Config');

+ 1 - 1
src/server/service/config-manager.js

@@ -1,5 +1,5 @@
 const debug = require('debug')('growi:service:ConfigManager');
-const pathUtils = require('@commons/util/path-utils');
+const pathUtils = require('growi-commons').pathUtils;
 const ConfigLoader = require('../service/config-loader');
 
 const KEYS_FOR_SAML_USE_ONLY_ENV_OPTION = [

+ 1 - 1
src/server/util/middlewares.js

@@ -1,6 +1,6 @@
 const debug = require('debug')('growi:lib:middlewares');
 const logger = require('@alias/logger')('growi:lib:middlewares');
-const pathUtils = require('@commons/util/path-utils');
+const pathUtils = require('growi-commons').pathUtils;
 const md5 = require('md5');
 const entities = require('entities');
 

+ 7 - 13
src/test/models/page.test.js

@@ -14,7 +14,6 @@ describe('Page', () => {
 
   let createdPages;
   let createdUsers;
-  let createdUserGroups;
 
   before(async() => {
     await conn.collection('pages').remove();
@@ -30,19 +29,14 @@ describe('Page', () => {
     const testUser0 = createdUsers[0];
     const testUser1 = createdUsers[1];
 
-    const groupFixture = [
-      {
-        image: '',
-        name: 'TestGroup0',
-      },
-      {
-        image: '',
-        name: 'TestGroup1',
-      },
-    ];
-    createdUserGroups = await testDBUtil.generateFixture(conn, 'UserGroup', groupFixture);
+    const UserGroup = conn.model('UserGroup');
+    let testGroup0 = new UserGroup();
+    testGroup0.name = 'TestGroup0';
+    let testGroup1 = new UserGroup();
+    testGroup1.name = 'TestGroup1';
+    testGroup0 = await testGroup0.save();
+    testGroup1 = await testGroup1.save();
 
-    const testGroup0 = createdUserGroups[0];
     const userGroupRelationFixture = [
       {
         relatedGroup: testGroup0,

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

@@ -1,32 +0,0 @@
-const chai = require('chai');
-const sinonChai = require('sinon-chai');
-
-const expect = chai.expect;
-
-chai.use(sinonChai);
-
-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();
-    });
-
-    it('should remove trailing slash', (done) => {
-      expect(pathUtils.normalizePath('/hoge/fuga/')).to.equal('/hoge/fuga');
-      done();
-    });
-
-    it('should remove unnecessary slashes', (done) => {
-      expect(pathUtils.normalizePath('//hoge/fuga//')).to.equal('/hoge/fuga');
-      done();
-    });
-  });
-});

+ 4 - 4
yarn.lock

@@ -4822,10 +4822,10 @@ graceful-fs@^4.1.15:
   resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
   integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==
 
-growi-commons@^3.0.0:
-  version "3.0.0"
-  resolved "https://registry.yarnpkg.com/growi-commons/-/growi-commons-3.0.0.tgz#58140100cba0483873b287153abb7974b3e0b8ef"
-  integrity sha512-4Ftok0fWzFGsv1UdGrhcRCC9YFB+nmGLdfg5NqyO0rPnSAkklu4TjmOZYdUKDDhBRwDphIAFWW7ZAlXtouY7lQ==
+growi-commons@^3.1.0:
+  version "3.1.0"
+  resolved "https://registry.yarnpkg.com/growi-commons/-/growi-commons-3.1.0.tgz#f75756d7c34aa2f96612243968b3e7b8c36a5280"
+  integrity sha512-x57/t8is1SIAA7NkdTCgCNAWpETNbUb7mnd6X4wbc7z5WbiqURB6GBECR7uNxLvGDFl6/6ngknOZLy+AmhB/ng==
 
 growl@1.10.5:
   version "1.10.5"