Seanny123
Seanny123

Reputation: 9336

Create SVG elements with TypeScript

I'm trying to create a properly formatted SVG element in TypeScript:

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

However, I get the following error in tslint

Forbidden http url in string: 'http://www.w3.org/2000/svg'

How do I avoid this error? I thought I required this URL to meet the SVG standard?

Upvotes: 4

Views: 3096

Answers (1)

theRealRobG
theRealRobG

Reputation: 622

tslint is complaining due to the no-http-string rule. The rule is defined as:

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/?."]

(Source: https://github.com/Microsoft/tslint-microsoft-contrib/blob/master/README.md)

Therefore, assuming you trust the World Wide Web Consortium, you could give it an exception in your tslint.json like

"no-http-string": [true, "http://www.w3.org/.*"]

Upvotes: 5

Related Questions