-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from ensdomains/mdt/xml-parser-svg-detection
add xml-parser to detect any svg content, with or without mimetype
- Loading branch information
Showing
15 changed files
with
123 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ | |
"info": { | ||
"version": "0.0.1-alpha.1", | ||
"title": "ENS Metadata Service", | ||
"description": "Set of endpoints to query ENS metadata and more", | ||
"description": "Set of endpoints to query ENS metadata and more.<br/><br/><b>Important:</b> While we have taken extensive measures to sanitize the user provided content, developers are advised to exercise caution when interacting with this API endpoint. In case of any advise or question, please reach us.", | ||
"contact": "[email protected]", | ||
"license": "MIT License", | ||
"license": { | ||
"name": "MIT", | ||
"url": "https://opensource.org/license/mit" | ||
}, | ||
"x-logo": { | ||
"url": "/assets/logo.svg", | ||
"backgroundColor": "#FFFFFF", | ||
|
@@ -528,9 +531,7 @@ | |
"type": "string", | ||
"enum": [ | ||
"mainnet", | ||
"rinkeby", | ||
"ropsten", | ||
"goerli" | ||
"sepolia" | ||
], | ||
"xml": { | ||
"name": "networkName" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// @ref: https://github.com/sindresorhus/is-svg | ||
// @ref: https://github.com/sindresorhus/is-svg/pull/38 | ||
import { XMLParser, XMLValidator } from 'fast-xml-parser'; | ||
|
||
export default function isSvg(data: string) { | ||
if (typeof data !== 'string') { | ||
throw new TypeError(`Expected a \`string\`, got \`${typeof data}\``); | ||
} | ||
|
||
data = data.toLowerCase().trim(); | ||
|
||
if (data.length === 0) { | ||
return false; | ||
} | ||
|
||
// Has to be `!==` as it can also return an object with error info. | ||
if (XMLValidator.validate(data) !== true) { | ||
return false; | ||
} | ||
|
||
let jsonObject; | ||
const parser = new XMLParser(); | ||
|
||
try { | ||
jsonObject = parser.parse(data); | ||
} catch { | ||
return false; | ||
} | ||
|
||
if (!jsonObject) { | ||
return false; | ||
} | ||
|
||
if (!('svg' in jsonObject)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters