Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #13 from bookmoons/url
Browse files Browse the repository at this point in the history
Add url fuzzer
  • Loading branch information
Yevgeny Pats authored Nov 10, 2019
2 parents 8f8c020 + 2c856f5 commit 4087bbe
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/url/fuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const url = require('url')

async function fuzz (bytes) {
const string = String.fromCodePoint(...bytes)
try {
whatwg(string)
params(string)
legacy(string)
} catch (error) {
if (!acceptable(error)) throw error
}
}

function whatwg (string) {
const parsed = new url.URL(string)
parsed.toString()
parsed.toJSON()
}

function params (string) {
const parsed = new url.URLSearchParams(string)
parsed.toString()
}

function legacy (string) {
/* eslint-disable-next-line node/no-deprecated-api */
const parsed = url.parse(string)
url.format(parsed)
}

function acceptable (error) {
return (
error instanceof URIError ||
expected.code.includes(error.code)
)
}

const expected = {
code: [
'ERR_INVALID_URL'
]
}

exports.fuzz = fuzz
6 changes: 6 additions & 0 deletions examples/url/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "url-fuzz",
"version": "1.0.0",
"main": "fuzz.js",
"license": "ISC"
}

0 comments on commit 4087bbe

Please sign in to comment.