diff --git a/find-tag-by-name.js b/find-tag-by-name.js index 5e87961..5eddcb6 100644 --- a/find-tag-by-name.js +++ b/find-tag-by-name.js @@ -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, ""); // we can't have more openings than closings if (closings >= openings) break; startIndex = relativeEnd;