Skip to content

Commit

Permalink
fixed edge case bug with tag names that start the same
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Dec 6, 2022
1 parent 080e0f8 commit 1c004bc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions find-tag-by-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function findTagByName(xml, tagName, options) {
let closings = 0;
while ((relativeEnd = indexOfMatchEnd(afterStart, "[ /]" + tagName + ">", startIndex)) !== -1) {
const clip = afterStart.substring(startIndex, relativeEnd + 1);
openings += countSubstring(clip, "<" + tagName);
closings += countSubstring(clip, "/" + tagName + ">");
openings += countSubstring(clip, "<" + tagName + "[ \n\t>]");
closings += countSubstring(clip, "</" + tagName + ">");
// we can't have more openings than closings
if (closings >= openings) break;
startIndex = relativeEnd;
Expand Down

0 comments on commit 1c004bc

Please sign in to comment.