1
1
import { warn , format , isBoolean } from '@intlify/shared'
2
- import { baseCompile , defaultOnError } from '@intlify/message-compiler'
2
+ import {
3
+ baseCompile ,
4
+ defaultOnError ,
5
+ detectHtmlTag
6
+ } from '@intlify/message-compiler'
3
7
4
8
import type { CompileOptions , CompileError } from '@intlify/message-compiler'
5
9
import type { MessageFunction , MessageFunctions } from './runtime'
6
10
7
- const RE_HTML_TAG = / < \/ ? [ \w \s = " / . ' : ; # -\/ ] + > /
8
11
const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`
9
12
10
- function checkHtmlMessage ( source : string , options : CompileOptions ) : void {
11
- const warnHtmlMessage = isBoolean ( options . warnHtmlMessage )
12
- ? options . warnHtmlMessage
13
- : true
14
- if ( warnHtmlMessage && RE_HTML_TAG . test ( source ) ) {
13
+ function checkHtmlMessage ( source : string , warnHtmlMessage ?: boolean ) : void {
14
+ if ( warnHtmlMessage && detectHtmlTag ( source ) ) {
15
15
warn ( format ( WARN_MESSAGE , { source } ) )
16
16
}
17
17
}
@@ -37,7 +37,12 @@ export function compileToFunction<T = string>(
37
37
return ( ( ) => source ) as MessageFunction < T >
38
38
} else {
39
39
// check HTML message
40
- __DEV__ && checkHtmlMessage ( source , options )
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ const warnHtmlMessage = isBoolean ( ( options as any ) . warnHtmlMessage )
42
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ ( options as any ) . warnHtmlMessage
44
+ : true
45
+ __DEV__ && checkHtmlMessage ( source , warnHtmlMessage )
41
46
42
47
// check caches
43
48
const onCacheKey = options . onCacheKey || defaultOnCacheKey
0 commit comments