Skip to content

Commit 1a9389b

Browse files
authored
Merge pull request #12 from gtramontina/main
Fix: drop global flag from html-detecting regexp
2 parents e04d152 + 9d0d872 commit 1a9389b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { compile } = require('@kitajs/html')
88

99
import './declaration'
1010

11-
const isHTMLRegex = /<[^>]*>/g
11+
const isHTMLRegex = /<[^>]*>/
1212
const isHTML = isHTMLRegex.test.bind(isHTMLRegex)
1313

1414
export const html = () =>

test/index.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,15 @@ describe('HTML', () => {
4949
const res = await app.handle(req('/'))
5050
expect(res.headers.get('Content-type')).toContain('text/html; charset=utf8')
5151
})
52+
53+
it('consistently identifies html content', async () => {
54+
const app = new Elysia().use(html()).get('/', () => `<h1>Hi</h1>`)
55+
56+
let res = await app.handle(req('/'))
57+
expect(res.headers.get('Content-type')).toContain('text/html; charset=utf8')
58+
res = await app.handle(req('/'))
59+
expect(res.headers.get('Content-type')).toContain('text/html; charset=utf8')
60+
res = await app.handle(req('/'))
61+
expect(res.headers.get('Content-type')).toContain('text/html; charset=utf8')
62+
})
5263
})

0 commit comments

Comments
 (0)