Bug description
In lib/index.js, parseFrontmatter() builds a RegExp from a string:
const line = fm.match(new RegExp('^' + key + ':\s*(.+)$', 'm'));
In JavaScript string literals, \s is not an escape sequence and becomes s.
The resulting regex is /^key:s*(.+)$/m instead of /^key:\s*(.+)$/m.
This can drop the leading s from a frontmatter value when the value starts
with s and has no space after the colon, e.g. description:search GitHub repos.
Reproduction
const re = new RegExp('^description:\s*(.+)$', 'm');
console.log(re); // /^description:s*(.+)$/m
console.log('description:search repos'.match(re)?.[1]); // "earch repos"
Expected behavior
The regex should match zero or more whitespace characters (\s*), not zero or
more literal s characters.
Environment
- github-explore v3.1.0
- Installed as a dsh profile bundle on Windows
Suggested fix
- const line = fm.match(new RegExp('^' + key + ':\s*(.+)$', 'm'));
+ const line = fm.match(new RegExp('^' + key + ':\\s*(.+)$', 'm'));
Bug description
In
lib/index.js,parseFrontmatter()builds a RegExp from a string:In JavaScript string literals,
\sis not an escape sequence and becomess.The resulting regex is
/^key:s*(.+)$/minstead of/^key:\s*(.+)$/m.This can drop the leading
sfrom a frontmatter value when the value startswith
sand has no space after the colon, e.g.description:search GitHub repos.Reproduction
Expected behavior
The regex should match zero or more whitespace characters (
\s*), not zero ormore literal
scharacters.Environment
Suggested fix