Skip to content

Commit

Permalink
Escape regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshun committed Jul 8, 2018
1 parent 30cb305 commit cae7d27
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
7 changes: 1 addition & 6 deletions lib/core/Head.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ const React = require('react');
class Head extends React.Component {
render() {
const links = this.props.config.headerLinks;
let hasBlog = false;
links.forEach(link => {
if (link.blog) {
hasBlog = true;
}
});
const hasBlog = links.some(link => link.blog);

let highlight = {
version: '9.12.0',
Expand Down
8 changes: 2 additions & 6 deletions lib/rename-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

const chalk = require('chalk');
const program = require('commander');
const escapeStringRegexp = require('escape-string-regexp');
const fs = require('fs');
const glob = require('glob');
const path = require('path');
Expand All @@ -17,11 +18,6 @@ const metadataUtils = require('./server/metadataUtils.js');

const CWD = process.cwd();

// escape appropriate characters in a string to be used in a regex
function escapeRegexp(s) {
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}

// generate a doc header from metadata
function makeHeader(metadata) {
let header = '---\n';
Expand Down Expand Up @@ -124,7 +120,7 @@ if (fs.existsSync(currentSidebarFile)) {
fs.renameSync(currentSidebarFile, newSidebarFile);
let sidebarContent = fs.readFileSync(newSidebarFile, 'utf8');
sidebarContent = sidebarContent.replace(
new RegExp(`version-${escapeRegexp(currentVersion)}-`, 'g'),
new RegExp(`version-${escapeStringRegexp(currentVersion)}-`, 'g'),
`version-${newVersion}-`
);
fs.writeFileSync(newSidebarFile, sidebarContent);
Expand Down

0 comments on commit cae7d27

Please sign in to comment.