Gathering detailed insights and metrics for encodeurl
Gathering detailed insights and metrics for encodeurl
Gathering detailed insights and metrics for encodeurl
Gathering detailed insights and metrics for encodeurl
Encode a URL to a percent-encoded form, excluding already-encoded sequences
npm install encodeurl
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
36 Stars
42 Commits
15 Forks
9 Watching
1 Branches
24 Contributors
Updated on 13 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-2.6%
10,199,152
Compared to previous day
Last week
3.5%
54,939,592
Compared to previous week
Last month
15.7%
224,606,811
Compared to previous month
Last year
18.9%
1,670,583,016
Compared to previous year
Encode a URL to a percent-encoded form, excluding already-encoded sequences.
1npm install encodeurl
1var encodeUrl = require('encodeurl')
Encode a URL to a percent-encoded form, excluding already-encoded sequences.
This function accepts a URL and encodes all the non-URL code points (as UTF-8 byte sequences). It will not encode the "%" character unless it is not part of a valid sequence (%20
will be left as-is, but %foo
will be encoded as %25foo
).
This encode is meant to be "safe" and does not throw errors. It will try as hard as it can to properly encode the given URL, including replacing any raw, unpaired surrogate pairs with the Unicode replacement character prior to encoding.
1var encodeUrl = require('encodeurl') 2var escapeHtml = require('escape-html') 3 4http.createServer(function onRequest (req, res) { 5 // get encoded form of inbound url 6 var url = encodeUrl(req.url) 7 8 // create html message 9 var body = '<p>Location ' + escapeHtml(url) + ' not found</p>' 10 11 // send a 404 12 res.statusCode = 404 13 res.setHeader('Content-Type', 'text/html; charset=UTF-8') 14 res.setHeader('Content-Length', String(Buffer.byteLength(body, 'utf-8'))) 15 res.end(body, 'utf-8') 16})
1var encodeUrl = require('encodeurl') 2var escapeHtml = require('escape-html') 3var url = require('url') 4 5http.createServer(function onRequest (req, res) { 6 // parse inbound url 7 var href = url.parse(req) 8 9 // set new host for redirect 10 href.host = 'localhost' 11 href.protocol = 'https:' 12 href.slashes = true 13 14 // create location header 15 var location = encodeUrl(url.format(href)) 16 17 // create html message 18 var body = '<p>Redirecting to new site: ' + escapeHtml(location) + '</p>' 19 20 // send a 301 21 res.statusCode = 301 22 res.setHeader('Content-Type', 'text/html; charset=UTF-8') 23 res.setHeader('Content-Length', String(Buffer.byteLength(body, 'utf-8'))) 24 res.setHeader('Location', location) 25 res.end(body, 'utf-8') 26})
This function is similar to the intrinsic function encodeURI
. However, it will not encode:
\
, ^
, or |
characters%
character when it's part of a valid sequence[
and ]
(for IPv6 hostnames)As a result, the encoding aligns closely with the behavior in the WHATWG URL specification. However, this package only encodes strings and does not do any URL parsing or formatting.
It is expected that any output from new URL(url)
will not change when used with this package, as the output has already been encoded. Additionally, if we were to encode before new URL(url)
, we do not expect the before and after encoded formats to be parsed any differently.
1$ npm test 2$ npm run lint
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
6 different organizations found -- score normalized to 10
Details
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
all dependencies are pinned
Details
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
no vulnerabilities detected
Reason
branch protection not enabled on development/release branches
Details
Reason
0 out of 3 merged PRs checked by a CI test -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
found 28 unreviewed changesets out of 30 -- score normalized to 0
Reason
no update tool detected
Details
Reason
project is not fuzzed
Details
Reason
0 commit(s) out of 30 and 0 issue activity out of 1 found in the last 90 days -- score normalized to 0
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2024-07-15T21:25:57Z
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More