Skip to content

Commit bb7a69f

Browse files
committed
Improve wildcard check
1 parent 17a778b commit bb7a69f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include-fragment-element.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ function getData(el) {
3737
}
3838
}
3939

40+
function isWildcard(accept) {
41+
return accept && !!accept.split(',').find(x => x.match(/^\s*\*\/\*/))
42+
}
43+
4044
export default class IncludeFragmentElement extends HTMLElement {
4145
constructor() {
4246
super()
@@ -127,7 +131,7 @@ export default class IncludeFragmentElement extends HTMLElement {
127131
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
128132
}
129133
const ct = response.headers.get('Content-Type')
130-
if (this.accept !== '*/*' && (!ct || !ct.match(this.accept ? this.accept : /^text\/html/))) {
134+
if (!isWildcard(this.accept) && (!ct || !ct.match(this.accept ? this.accept : /^text\/html/))) {
131135
throw new Error(`Failed to load resource: expected ${this.accept || 'text/html'} but was ${ct}`)
132136
}
133137
return response

0 commit comments

Comments
 (0)