Skip to content

Commit b5f8a77

Browse files
authored
Merge pull request #6 from soderlind/security/fix
Potential fix for code scanning alert no. 3: Incomplete string escaping or encoding
2 parents d9aca10 + 09ce24d commit b5f8a77

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
### Fixed
44
- wordpress.org tabbed theme now detects FAQ content even when the section is titled "Frequently Asked Questions" or appears out of the typical order. Sections are scanned globally and mapped to canonical tabs (description, installation, faq, changelog) irrespective of order.
55

6+
## [0.1.8] - 2025-10-21
7+
### Fixed
8+
- Auto-fix single-line fenced code now safely escapes backslashes before backticks preventing malformed inline code when content contains `\` and `` ` `` characters.
9+
- Validator emphasis balancing logic now uses a robust regex escape preventing false positives on tokens with special regex metacharacters.
10+
### Changed
11+
- README cleaned: removed outdated 0.1.5 update banner to keep intro concise.
12+
### Security
13+
- Addresses code scanning warning related to incomplete string escaping for inline code conversion and emphasis token detection.
14+
615

716
All notable changes to this project will be documented in this file.
817

@@ -76,6 +85,7 @@ The format is based on Keep a Changelog (https://keepachangelog.com/en/1.0.0/) a
7685

7786
[0.1.6]: https://github.com/soderlind/wordpress-readme-preview/compare/v0.1.5...v0.1.6
7887
[0.1.7]: https://github.com/soderlind/wordpress-readme-preview/compare/v0.1.6...v0.1.7
88+
[0.1.8]: https://github.com/soderlind/wordpress-readme-preview/compare/v0.1.7...v0.1.8
7989
[0.1.4]: https://github.com/soderlind/wordpress-readme-preview/compare/v0.1.3...v0.1.4
8090
[0.1.5]: https://github.com/soderlind/wordpress-readme-preview/compare/v0.1.4...v0.1.5
8191
[0.1.3]: https://github.com/soderlind/wordpress-readme-preview/compare/v0.1.1...v0.1.3

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "wordpress-readme-preview",
33
"displayName": "WordPress Readme",
44
"description": "Preview, validate, and edit WordPress readme.txt files with syntax highlighting, IntelliSense, and accurate rendering",
5-
"version": "0.1.7",
5+
"version": "0.1.8",
66
"publisher": "persoderlind",
77
"engines": {
88
"vscode": "^1.74.0"

src/autoFix.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export function autoFixReadme(raw: string, options?: { multiLineStyle?: 'indente
7474
} else if (block.length === 1) {
7575
// single line -> inline code
7676
const content = block[0].trim();
77-
const inline = '`' + content.replace(/`/g, '\\`') + '`';
77+
// Escape backslashes, then backticks
78+
const escapedContent = content.replace(/\\/g, '\\\\').replace(/`/g, '\\`');
79+
const inline = '`' + escapedContent + '`';
7880
output.push(inline);
7981
changes.push(`Converted single-line fenced block at line ${startIndex + 1} to inline code`);
8082
} else {

src/parser/validator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ export class ReadmeValidator {
461461
});
462462

463463
// 3. Unmatched emphasis markers (simple heuristic)
464-
const countMatches = (text: string, token: string) => (text.match(new RegExp(token.replace(/([*~`])/g,'\\$1'),'g')) || []).length;
464+
function escapeRegExp(s: string): string {
465+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
466+
}
467+
const countMatches = (text: string, token: string) => (text.match(new RegExp(escapeRegExp(token),'g')) || []).length;
465468
const totalDoubleAsterisk = countMatches(readme.rawContent, '**');
466469
if (totalDoubleAsterisk % 2 === 1) {
467470
warnings.push({

0 commit comments

Comments
 (0)