Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Invalid regular expression flags #4123

Closed
sdlyfjx opened this issue Feb 11, 2020 · 5 comments
Closed

SyntaxError: Invalid regular expression flags #4123

sdlyfjx opened this issue Feb 11, 2020 · 5 comments

Comments

@sdlyfjx
Copy link

@sdlyfjx sdlyfjx commented Feb 11, 2020

FATAL Invalid regular expression flags
node_modules\hexo\lib\plugins\filter\after_render\meta_generator.js:10

I upgrade my hexo from 3.8 to 4.2 .
First I find this error when I use NodeJS8.9.0 and check the Issues then I find the resolution:upgrade my nodejs version to 8.17.0 and it worked.
But I need run hexo on TencentCloud Serverless Framework which only have nodejs6.10 and 8.9.0 environment. So I must fixed this problom.

Becouse of node8.9.0 not support the regular flags 's', it only have 'i' 'm' and 'g'.
Then I delete the /s in the RegExp and it worked fine.
So can we fixed this probloms?

Sorry for my bad english.

因为腾讯云SCF上只有Node8.9.0的运行环境,Hexo升级4.2后在那个meta_generator.js中的正则表达式用了/s的单行匹配模式,但是Node8.9.0不支持这个模式(默认就是单行吧?除非/m启用多行匹配),所以能不能把这个问题修复一下?蟹蟹。

@stevenjoezhang

This comment has been minimized.

Copy link
Contributor

@stevenjoezhang stevenjoezhang commented Feb 11, 2020

Both Node.js6 and 8 are outdated: https://nodejs.org/en/about/releases/
This is a serious security issue, and I suggest you send a ticket to Tencent Cloud to point out the problem.

@sdlyfjx

This comment has been minimized.

Copy link
Author

@sdlyfjx sdlyfjx commented Feb 11, 2020

Er......
I understand the NodeJS8 out of date and may have some security issues.
但是现在这个问题不会导致安全问题吧?Node高版本中也会支持Node8.9的正则写法,只不过加入了/s模式来进行单行匹配。即使不写/s的话高版本是不是也默认进行单行匹配?
所以如果官方可以把这个/s去掉,是不是不会影响什么问题?
而且这个组件仅仅是在渲染完后在中加入一个Hexo版本号的标签。
功能可以有,但不是必须。但加入了这个功能却导致了低版本的兼容性。

这个正则表达式如果不用/s模式是不是确实会导致安全性问题?这个我还不是特别清楚。还请告知。

Himself65 added a commit to Himself65/hexo that referenced this issue Feb 21, 2020
@Himself65

This comment has been minimized.

Copy link
Contributor

@Himself65 Himself65 commented Feb 21, 2020

hexo will not support < 8 and you can use @babel/helper-create-regexp-features-plugin to compatible code

see: https://www.npmjs.com/package/@babel/helper-create-regexp-features-plugin

and this issue should be closed

@Himself65

This comment has been minimized.

Copy link
Contributor

@Himself65 Himself65 commented Feb 21, 2020

and single-line mode cannot remove directly, see this example

// Test for Issue #3777
it('multi-line head', () => {
const content = '<head>\n<link>\n</head>';
hexo.config.meta_generator = true;
const result = metaGenerator(content);
const $ = cheerio.load(result);
$('meta[name="generator"]').length.should.eql(1);
const expected = '<head>\n<link>\n<meta name="generator" content="Hexo ' + hexo.version + '"></head>';
result.should.eql(expected);
});

@sdlyfjx

This comment has been minimized.

Copy link
Author

@sdlyfjx sdlyfjx commented Feb 21, 2020

@Himself65 Thank you for your answer and your pr. Although it has been closed, but it works for me.
Thanks very much.

这个用正则替换在head里加上generator的功能,粗暴一点直接先找到head里面里面有name="generator"的给去掉,然后直接把替换成不就好啦?

@sdlyfjx sdlyfjx closed this Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.