File tree Expand file tree Collapse file tree 2 files changed +51
-3
lines changed Expand file tree Collapse file tree 2 files changed +51
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ import { isReactLocalization } from "./localization";
5
5
import { parseMarkup } from "./markup" ;
6
6
import VOID_ELEMENTS from "../vendor/voidElementTags" ;
7
7
8
+ // Match the opening angle bracket (<) in HTML tags, and HTML entities like
9
+ // &, &, &.
10
+ const reMarkup = / < | & # ? \w + ; / ;
11
+
8
12
/*
9
13
* Prepare props passed to `Localized` for formatting.
10
14
*/
@@ -127,9 +131,9 @@ export default class Localized extends Component {
127
131
return cloneElement ( elem , localizedProps ) ;
128
132
}
129
133
130
- // If the message value doesn't contain any markup, insert it as the only
131
- // child of the wrapped component.
132
- if ( ! messageValue . includes ( "<" ) ) {
134
+ // If the message value doesn't contain any markup nor any HTML entities,
135
+ // insert it as the only child of the wrapped component.
136
+ if ( ! reMarkup . test ( messageValue ) ) {
133
137
return cloneElement ( elem , localizedProps , messageValue ) ;
134
138
}
135
139
Original file line number Diff line number Diff line change @@ -29,6 +29,50 @@ true = 0 < 3 is true.
29
29
) ) ;
30
30
} ) ;
31
31
32
+ test ( '& in text' , function ( ) {
33
+ const mcx = new MessageContext ( ) ;
34
+ const l10n = new ReactLocalization ( [ mcx ] ) ;
35
+
36
+ mcx . addMessages ( `
37
+ megaman = Jumping & Shooting
38
+ ` )
39
+
40
+ const wrapper = shallow (
41
+ < Localized id = "megaman" >
42
+ < div />
43
+ </ Localized > ,
44
+ { context : { l10n } }
45
+ ) ;
46
+
47
+ assert . ok ( wrapper . contains (
48
+ < div >
49
+ Jumping & Shooting
50
+ </ div >
51
+ ) ) ;
52
+ } ) ;
53
+
54
+ test ( 'HTML entity' , function ( ) {
55
+ const mcx = new MessageContext ( ) ;
56
+ const l10n = new ReactLocalization ( [ mcx ] ) ;
57
+
58
+ mcx . addMessages ( `
59
+ two = First · Second
60
+ ` )
61
+
62
+ const wrapper = shallow (
63
+ < Localized id = "two" >
64
+ < div />
65
+ </ Localized > ,
66
+ { context : { l10n } }
67
+ ) ;
68
+
69
+ assert . ok ( wrapper . contains (
70
+ < div >
71
+ First · Second
72
+ </ div >
73
+ ) ) ;
74
+ } ) ;
75
+
32
76
test ( 'one element is matched' , function ( ) {
33
77
const mcx = new MessageContext ( ) ;
34
78
const l10n = new ReactLocalization ( [ mcx ] ) ;
You can’t perform that action at this time.
0 commit comments