Skip to content

Commit

Permalink
fix: issues with special-char-escape rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Kimbrell committed Oct 2, 2023
1 parent febc3e2 commit b575900
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions src/rules/special-char-escape.ts
Expand Up @@ -8,32 +8,46 @@ const rule: Rule = {
parser.addListener('text', (event) => {
const raw = event.raw;
const reSpecChar = /[<>]| \& /g;
let match;

while (match = reSpecChar.exec(raw)) {
const fixedPos = parser.fixPos(event, match.index);
let tags = [];

try {
const tags = parse(raw);
try {
let index = 0;

if(tags.length) {
for(const tag of tags) {
const start = raw.indexOf(tag);
const end = start + tag.length - 1;
tags = parse(raw).map(tag => {
const sliced = raw.slice(index);

if(match.index >= start && match.index <= end) {
continue;
}
const start = index;
const end = index + tag.length;

reporter.error(`Special characters must be escaped : [ ${match[0]} ].`, fixedPos.line, fixedPos.col, this, event.raw);
}
index += tag.length + sliced.indexOf(tag);

return {
start,
end,
tag
}
else {
reporter.error(`Special characters must be escaped : [ ${match[0]} ].`, fixedPos.line, fixedPos.col, this, event.raw);
}).filter(Boolean)
}
catch(e) {
// Do nothing
}

let match;

while (match = reSpecChar.exec(raw)) {
for(const {start, end, tag} of tags) {
if(tag.match(/^<#?[a-zA-]/)) {
continue;
}
}
catch(e) {
// Do nothing

if(!(match.index >= start && match.index <= end)) {
continue;
}

const { line, col } = parser.fixPos(event, match.index);

reporter.error(`Special characters must be escaped : [ ${match[0]} ].`, line, col, this, event.raw);
}
}
});
Expand Down

0 comments on commit b575900

Please sign in to comment.