Explorar el Código

use escape-string-regexp

Yuki Takei hace 8 años
padre
commit
060cbcc49d
Se han modificado 2 ficheros con 8 adiciones y 8 borrados
  1. 3 1
      resource/js/components/PageList/PagePath.js
  2. 5 7
      resource/js/legacy/crowi.js

+ 3 - 1
resource/js/components/PageList/PagePath.js

@@ -1,6 +1,8 @@
 import React from 'react';
 import React from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 
 
+import * as escapeStringRegexp from 'escape-string-regexp';
+
 export default class PagePath extends React.Component {
 export default class PagePath extends React.Component {
 
 
   getShortPath(path) {
   getShortPath(path) {
@@ -29,7 +31,7 @@ export default class PagePath extends React.Component {
     const page = this.props.page;
     const page = this.props.page;
     const pagePath = page.path.replace(this.props.excludePathString.replace(/^\//, ''), '');
     const pagePath = page.path.replace(this.props.excludePathString.replace(/^\//, ''), '');
     const shortPath = this.getShortPath(pagePath);
     const shortPath = this.getShortPath(pagePath);
-    const shortPathEscaped = shortPath.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
+    const shortPathEscaped = escapeStringRegexp(shortPath);
     const pathPrefix = pagePath.replace(new RegExp(shortPathEscaped + '(/)?$'), '');
     const pathPrefix = pagePath.replace(new RegExp(shortPathEscaped + '(/)?$'), '');
 
 
     return (
     return (

+ 5 - 7
resource/js/legacy/crowi.js

@@ -2,9 +2,10 @@
 /* Author: Sotaro KARASAWA <sotarok@crocos.co.jp>
 /* Author: Sotaro KARASAWA <sotarok@crocos.co.jp>
 */
 */
 
 
-var io = require('socket.io-client');
-var entities = require("entities");
-var getLineFromPos = require('get-line-from-pos');
+const io = require('socket.io-client');
+const entities = require("entities");
+const escapeStringRegexp = require('escape-string-regexp');
+const getLineFromPos = require('get-line-from-pos');
 require('bootstrap-sass');
 require('bootstrap-sass');
 require('jquery.cookie');
 require('jquery.cookie');
 
 
@@ -474,11 +475,8 @@ $(function() {
       return;
       return;
     }
     }
 
 
-    var escape = function(s) {
-      return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
-    };
     path = entities.encodeHTML(path);
     path = entities.encodeHTML(path);
-    var pattern = escape(entities.encodeHTML(shortPath)) + '(/)?$';
+    var pattern = escapeStringRegexp(entities.encodeHTML(shortPath)) + '(/)?$';
 
 
     $link.html(path.replace(new RegExp(pattern), '<strong>' + shortPath + '$1</strong>'));
     $link.html(path.replace(new RegExp(pattern), '<strong>' + shortPath + '$1</strong>'));
   });
   });