File tree Expand file tree Collapse file tree 3 files changed +26
-56
lines changed
Expand file tree Collapse file tree 3 files changed +26
-56
lines changed Original file line number Diff line number Diff line change 66 */
77
88import {
9- ATTRIBUTE_NAME_CHAR ,
10- ATTRIBUTE_NAME_START_CHAR ,
119 ID_ATTRIBUTE_NAME ,
1210 ROOT_ATTRIBUTE_NAME ,
1311 getPropertyInfo ,
1412 shouldSetAttribute ,
13+ isAttributeNameSafe ,
1514} from '../shared/DOMProperty' ;
16- import warning from 'fbjs/lib/warning' ;
17-
18- // isAttributeNameSafe() is currently duplicated in DOMMarkupOperations.
19- // TODO: Find a better place for this.
20- const VALID_ATTRIBUTE_NAME_REGEX = new RegExp (
21- '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$' ,
22- ) ;
23- const illegalAttributeNameCache = { } ;
24- const validatedAttributeNameCache = { } ;
25- function isAttributeNameSafe ( attributeName ) {
26- if ( validatedAttributeNameCache . hasOwnProperty ( attributeName ) ) {
27- return true ;
28- }
29- if ( illegalAttributeNameCache . hasOwnProperty ( attributeName ) ) {
30- return false ;
31- }
32- if ( VALID_ATTRIBUTE_NAME_REGEX . test ( attributeName ) ) {
33- validatedAttributeNameCache [ attributeName ] = true ;
34- return true ;
35- }
36- illegalAttributeNameCache [ attributeName ] = true ;
37- if ( __DEV__ ) {
38- warning ( false , 'Invalid attribute name: `%s`' , attributeName ) ;
39- }
40- return false ;
41- }
4215
4316// shouldIgnoreValue() is currently duplicated in DOMMarkupOperations.
4417// TODO: Find a better place for this.
Original file line number Diff line number Diff line change 66 */
77
88import {
9- ATTRIBUTE_NAME_CHAR ,
10- ATTRIBUTE_NAME_START_CHAR ,
119 ID_ATTRIBUTE_NAME ,
1210 ROOT_ATTRIBUTE_NAME ,
1311 getPropertyInfo ,
1412 shouldAttributeAcceptBooleanValue ,
1513 shouldSetAttribute ,
14+ isAttributeNameSafe ,
1615} from '../shared/DOMProperty' ;
1716import quoteAttributeValueForBrowser from './quoteAttributeValueForBrowser' ;
18- import warning from 'fbjs/lib/warning' ;
19-
20- // isAttributeNameSafe() is currently duplicated in DOMPropertyOperations.
21- // TODO: Find a better place for this.
22- const VALID_ATTRIBUTE_NAME_REGEX = new RegExp (
23- '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$' ,
24- ) ;
25- const illegalAttributeNameCache = { } ;
26- const validatedAttributeNameCache = { } ;
27- function isAttributeNameSafe ( attributeName ) {
28- if ( validatedAttributeNameCache . hasOwnProperty ( attributeName ) ) {
29- return true ;
30- }
31- if ( illegalAttributeNameCache . hasOwnProperty ( attributeName ) ) {
32- return false ;
33- }
34- if ( VALID_ATTRIBUTE_NAME_REGEX . test ( attributeName ) ) {
35- validatedAttributeNameCache [ attributeName ] = true ;
36- return true ;
37- }
38- illegalAttributeNameCache [ attributeName ] = true ;
39- if ( __DEV__ ) {
40- warning ( false , 'Invalid attribute name: `%s`' , attributeName ) ;
41- }
42- return false ;
43- }
4417
4518// shouldIgnoreValue() is currently duplicated in DOMPropertyOperations.
4619// TODO: Find a better place for this.
Original file line number Diff line number Diff line change @@ -111,6 +111,30 @@ export const ATTRIBUTE_NAME_CHAR =
111111
112112export const ID_ATTRIBUTE_NAME = 'data-reactid' ;
113113export const ROOT_ATTRIBUTE_NAME = 'data-reactroot' ;
114+ export const VALID_ATTRIBUTE_NAME_REGEX = new RegExp (
115+ '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$' ,
116+ ) ;
117+
118+ const illegalAttributeNameCache = { } ;
119+ const validatedAttributeNameCache = { } ;
120+
121+ export function isAttributeNameSafe ( attributeName ) {
122+ if ( validatedAttributeNameCache . hasOwnProperty ( attributeName ) ) {
123+ return true ;
124+ }
125+ if ( illegalAttributeNameCache . hasOwnProperty ( attributeName ) ) {
126+ return false ;
127+ }
128+ if ( VALID_ATTRIBUTE_NAME_REGEX . test ( attributeName ) ) {
129+ validatedAttributeNameCache [ attributeName ] = true ;
130+ return true ;
131+ }
132+ illegalAttributeNameCache [ attributeName ] = true ;
133+ if ( __DEV__ ) {
134+ warning ( false , 'Invalid attribute name: `%s`' , attributeName ) ;
135+ }
136+ return false ;
137+ }
114138
115139/**
116140 * Map from property "standard name" to an object with info about how to set
You can’t perform that action at this time.
0 commit comments