Skip to content

Commit c34f0ae

Browse files
feat: handle uppercase tags and uppercase attributes (#232)
BREAKING CHANGE: uppercase tags and uppercase tags are handled now
1 parent 8e5a0cd commit c34f0ae

File tree

7 files changed

+448
-330
lines changed

7 files changed

+448
-330
lines changed

src/utils.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export function getLinks(content, attributes) {
367367
: attributes;
368368

369369
function processMatch(match, strUntilValue, name, value, index) {
370-
if (!this.isRelevantTagAttr(this.currentTag, name)) {
370+
if (!this.isRelevantTagAttribute(this.currentTag, name)) {
371371
return;
372372
}
373373

@@ -428,16 +428,14 @@ export function getLinks(content, attributes) {
428428
return parser.parse('outside', content, {
429429
currentTag: null,
430430
results: [],
431-
isRelevantTagAttr: (tag, attribute) => {
432-
const res = tagsAndAttributes.find((a) => {
433-
if (a.startsWith(':')) {
434-
return attribute === a.slice(1);
435-
}
431+
isRelevantTagAttribute: (tag, attribute) => {
432+
return tagsAndAttributes.some((item) => {
433+
const pattern = new RegExp(`^${item}$`, 'i');
436434

437-
return `${tag}:${attribute}` === a;
435+
return (
436+
pattern.test(`${tag}:${attribute}`) || pattern.test(`:${attribute}`)
437+
);
438438
});
439-
440-
return Boolean(res);
441439
},
442440
}).results;
443441
}

test/__snapshots__/attributes-option.test.js.snap

Lines changed: 168 additions & 114 deletions
Large diffs are not rendered by default.

test/__snapshots__/esModule-option.test.js.snap

Lines changed: 69 additions & 51 deletions
Large diffs are not rendered by default.

test/__snapshots__/loader.test.js.snap

Lines changed: 23 additions & 17 deletions
Large diffs are not rendered by default.

test/__snapshots__/minimize-option.test.js.snap

Lines changed: 132 additions & 105 deletions
Large diffs are not rendered by default.

test/__snapshots__/root-option.test.js.snap

Lines changed: 46 additions & 34 deletions
Large diffs are not rendered by default.

test/fixtures/simple.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ <h2>An Ordered HTML List</h2>
3939
<img src="~aliasImg">
4040
<img src="">
4141
<img src="image.png">
42+
<IMG src="image.png">
43+
<img SRC="image.png">
44+
<IMG SRC="image.png">
4245

4346
<script src="script.js"></script>
4447

0 commit comments

Comments
 (0)