【问题标题】:Create SVG elements with TypeScript使用 TypeScript 创建 SVG 元素
【发布时间】:2017-03-06 14:20:51
【问题描述】:

我正在尝试在 TypeScript 中创建格式正确的 SVG 元素:

createSVGElement(tag) {
    return document.createElementNS("http://www.w3.org/2000/svg", tag);
}

但是,我在tslint 中收到以下错误

字符串中的禁止 http url:'http://www.w3.org/2000/svg'

如何避免此错误?我认为我需要此 URL 才能满足 SVG 标准?

【问题讨论】:

    标签: javascript svg typescript tslint


    【解决方案1】:

    tslintno-http-string 规则而抱怨。规则定义为:

    不要使用以“http:”开头的字符串。 URL 字符串应以“https:”开头。 Http 字符串可能是一个安全问题,表明您的软件可能遭受 cookie 窃取攻击。从 1.0 版开始,此规则将正则表达式列表作为参数。任何匹配该正则表达式的字符串都将被忽略。例如,要允许 http 连接到 example.com 和 examples.com,请像这样配置您的规则:"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/.*"]
    

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 1970-01-01
      • 2017-01-26
      • 1970-01-01
      • 2019-08-07
      • 2013-12-30
      • 2023-03-27
      • 1970-01-01
      • 2020-01-14
      相关资源
      最近更新 更多