| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0b07f47 commit ff12fe5
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,21 +19,10 @@ const STRING = 'string'; | |||
| 19 | 19 | const OBJECT = 'object'; | |
| 20 | 20 | ||
| 21 | 21 | function normalizeTagName(tagName: string): string { | |
| 22 | - tagName = tagName.toLowerCase(); | ||
| 23 | - if (tagName[0] === ':') { | ||
| 24 | - const [ns, name] = splitNsName(tagName, false); | ||
| 22 | + const tagNameLower = tagName.toLowerCase(); | ||
| 23 | + const [ns, name] = splitNsName(tagNameLower, false); | ||
| 25 | 24 | ||
| 26 | - return ns === SVG_NAMESPACE || ns === MATH_ML_NAMESPACE ? `:${ns}:${name}` : name; | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - const colonIdx = tagName.indexOf(':'); | ||
| 30 | - if (colonIdx > 0) { | ||
| 31 | - const ns = tagName.substring(0, colonIdx); | ||
| 32 | - const name = tagName.substring(colonIdx + 1); | ||
| 33 | - | ||
| 34 | - return ns === SVG_NAMESPACE || ns === MATH_ML_NAMESPACE ? `:${ns}:${name}` : name; | ||
| 35 | - } | ||
| 36 | - return tagName; | ||
| 25 | + return ns === SVG_NAMESPACE || ns === MATH_ML_NAMESPACE ? `:${ns}:${name}` : name; | ||
| 37 | 26 | } | |
| 38 | 27 | ||
| 39 | 28 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,23 +207,17 @@ If 'onAnything' is a directive input, make sure the directive is imported by the | |||
| 207 | 207 | describe('Custom XML / XHTML namespaces', () => { | |
| 208 | 208 | it('should support elements with custom namespaces', () => { | |
| 209 | 209 | expect(registry.hasElement(':xhtml:a', [])).toBeTruthy(); | |
| 210 | - expect(registry.hasElement('xhtml:a', [])).toBeTruthy(); | ||
| 211 | 210 | expect(registry.hasElement(':foo:div', [])).toBeTruthy(); | |
| 212 | - expect(registry.hasElement('foo:div', [])).toBeTruthy(); | ||
| 213 | 211 | }); | |
| 214 | 212 | ||
| 215 | 213 | it('should support properties on custom namespaced elements', () => { | |
| 216 | 214 | expect(registry.hasProperty(':xhtml:a', 'href', [])).toBeTruthy(); | |
| 217 | - expect(registry.hasProperty('xhtml:a', 'href', [])).toBeTruthy(); | ||
| 218 | 215 | expect(registry.hasProperty(':foo:div', 'id', [])).toBeTruthy(); | |
| 219 | - expect(registry.hasProperty('foo:div', 'id', [])).toBeTruthy(); | ||
| 220 | 216 | }); | |
| 221 | 217 | ||
| 222 | 218 | it('should return correct security contexts for custom namespaced elements', () => { | |
| 223 | 219 | expect(registry.securityContext(':xhtml:a', 'href', false)).toBe(SecurityContext.URL); | |
| 224 | - expect(registry.securityContext('xhtml:a', 'href', false)).toBe(SecurityContext.URL); | ||
| 225 | 220 | expect(registry.securityContext(':foo:div', 'innerHTML', false)).toBe(SecurityContext.HTML); | |
| 226 | - expect(registry.securityContext('foo:div', 'innerHTML', false)).toBe(SecurityContext.HTML); | ||
| 227 | 221 | }); | |
| 228 | 222 | }); | |
| 229 | 223 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,6 +73,7 @@ import { | |||
| 73 | 73 | } from './i18n_util'; | |
| 74 | 74 | import {createTNodeAtIndex} from '../tnode_manipulation'; | |
| 75 | 75 | import {allocExpando} from '../view/construction'; | |
| 76 | + import {MATH_ML_NAMESPACE, SVG_NAMESPACE} from '../namespaces'; | ||
| 76 | 77 | ||
| 77 | 78 | const BINDING_REGEXP = /�(\d+):?\d*�/gi; | |
| 78 | 79 | const ICU_REGEXP = /({\s*�\d+:?\d*�\s*,\s*\S{6}\s*,[\s\S]*})/gi; | |
@@ -984,9 +985,34 @@ function addCreateAttribute( | |||
| 984 | 985 | create.push((newIndex << IcuCreateOpCode.SHIFT_REF) | IcuCreateOpCode.Attr, attrName, attrValue); | |
| 985 | 986 | } | |
| 986 | 987 | ||
| 988 | + function splitNsName(elementName: string, fatal: boolean = true): [string | null, string] { | ||
| 989 | + if (elementName[0] != ':') { | ||
| 990 | + return [null, elementName]; | ||
| 991 | + } | ||
| 992 | + | ||
| 993 | + const colonIndex = elementName.indexOf(':', 1); | ||
| 994 | + | ||
| 995 | + if (colonIndex === -1) { | ||
| 996 | + if (fatal) { | ||
| 997 | + throw new Error(`Unsupported format "${elementName}" expecting ":namespace:name"`); | ||
| 998 | + } else { | ||
| 999 | + return [null, elementName]; | ||
| 1000 | + } | ||
| 1001 | + } | ||
| 1002 | + | ||
| 1003 | + return [elementName.slice(1, colonIndex), elementName.slice(colonIndex + 1)]; | ||
| 1004 | + } | ||
| 1005 | + | ||
| 1006 | + function normalizeTagName(tagName: string): string { | ||
| 1007 | + const tagNameLower = tagName.toLowerCase(); | ||
| 1008 | + const [ns, name] = splitNsName(tagNameLower, false); | ||
| 1009 | + | ||
| 1010 | + return ns === SVG_NAMESPACE || ns === MATH_ML_NAMESPACE ? `:${ns}:${name}` : name; | ||
| 1011 | + } | ||
| 1012 | + | ||
| 987 | 1013 | function i18nResolveSanitizer(attrName: string, tagName?: string): SanitizerFn | null { | |
| 988 | 1014 | const lowerAttrName = attrName.toLowerCase(); | |
| 989 | - const lowerTagName = tagName ? tagName.toLowerCase() : '*'; | ||
| 1015 | + const lowerTagName = tagName ? normalizeTagName(tagName) : '*'; | ||
| 990 | 1016 | const schema = SECURITY_SCHEMA(); | |
| 991 | 1017 | const schemaContext = | |
| 992 | 1018 | schema[`${lowerTagName}|${lowerAttrName}`] || | |
| Back | FazBrowse Home | New Git URL |
0 commit comments