使用 TypeScript 创建 SVG 元素
Create SVG elements with TypeScript
我正在尝试在 TypeScript 中创建格式正确的 SVG 元素:
createSVGElement(tag) {
return document.createElementNS("http://www.w3.org/2000/svg", tag);
}
但是,我在 tslint
中收到以下错误
Forbidden http url in string: 'http://www.w3.org/2000/svg'
如何避免此错误?我以为我需要这个 URL 来满足 SVG 标准?
tslint
正在抱怨 no-http-string
规则。规则定义为:
Do not use strings that start with 'http:'. URL strings should start with 'https:'. Http strings can be a security problem and indicator that your software may suffer from cookie-stealing attacks. Since version 1.0, this rule takes a list of regular expressions as a parameter. Any string matching that regular expression will be ignored. For example, to allow http connections to example.com and examples.com, configure your rule like this: "no-http-string": [true, "http://www.example.com/?.", "http://www.examples.com/?."]
(来源:https://github.com/Microsoft/tslint-microsoft-contrib/blob/master/README.md)
因此,假设您信任万维网联盟,您可以在 tslint.json
中给它一个例外
"no-http-string": [true, "http://www.w3.org/.*"]
我正在尝试在 TypeScript 中创建格式正确的 SVG 元素:
createSVGElement(tag) {
return document.createElementNS("http://www.w3.org/2000/svg", tag);
}
但是,我在 tslint
Forbidden http url in string: 'http://www.w3.org/2000/svg'
如何避免此错误?我以为我需要这个 URL 来满足 SVG 标准?
tslint
正在抱怨 no-http-string
规则。规则定义为:
Do not use strings that start with 'http:'. URL strings should start with 'https:'. Http strings can be a security problem and indicator that your software may suffer from cookie-stealing attacks. Since version 1.0, this rule takes a list of regular expressions as a parameter. Any string matching that regular expression will be ignored. For example, to allow http connections to example.com and examples.com, configure your rule like this: "no-http-string": [true, "http://www.example.com/?.", "http://www.examples.com/?."]
(来源:https://github.com/Microsoft/tslint-microsoft-contrib/blob/master/README.md)
因此,假设您信任万维网联盟,您可以在 tslint.json
中给它一个例外
"no-http-string": [true, "http://www.w3.org/.*"]