我正在尝试在 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
中给它一个异常(exception),例如
"no-http-string": [true, "http://www.w3.org/.*"]
关于javascript - 使用 TypeScript 创建 SVG 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40224636/