diff --git a/.editorconfig b/.editorconfig index 98a761d..1c6314a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[{package.json,*.yml}] +[*.yml] indent_style = space indent_size = 2 diff --git a/.github/funding.yml b/.github/funding.yml new file mode 100644 index 0000000..6d41774 --- /dev/null +++ b/.github/funding.yml @@ -0,0 +1 @@ +tidelift: npm/decode-uri-component diff --git a/.github/security.md b/.github/security.md new file mode 100644 index 0000000..5358dc5 --- /dev/null +++ b/.github/security.md @@ -0,0 +1,3 @@ +# Security Policy + +To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..0063223 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,27 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Node.js ${{ matrix.node-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: + - '18' + - '16' + - '14' + - '12' + - '10' + - '8' + - '6' + - '4' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..9cf9495 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 23875fc..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: node_js -node_js: - - '8' - - '6' - - '4' - - '0.12' - - '0.10' -after_script: - - npm run coveralls diff --git a/index.js b/index.js index 691499b..d33e06e 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ var multiMatcher = new RegExp('(' + token + ')+', 'gi'); function decodeComponents(components, split) { try { // Try to decode the entire string first - return decodeURIComponent(components.join('')); + return [decodeURIComponent(components.join(''))]; } catch (err) { // Do nothing } @@ -28,12 +28,12 @@ function decode(input) { try { return decodeURIComponent(input); } catch (err) { - var tokens = input.match(singleMatcher); + var tokens = input.match(singleMatcher) || []; for (var i = 1; i < tokens.length; i++) { input = decodeComponents(tokens, i).join(''); - tokens = input.match(singleMatcher); + tokens = input.match(singleMatcher) || []; } return input; diff --git a/license b/license index 78b0855..8dbcd53 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ The MIT License (MIT) -Copyright (c) Sam Verschueren (github.com/SamVerschueren) +Copyright (c) 2017, Sam Verschueren (github.com/SamVerschueren) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index 183bd7c..1666841 100644 --- a/package.json +++ b/package.json @@ -1,37 +1,37 @@ { - "name": "decode-uri-component", - "version": "0.2.0", - "description": "A better decodeURIComponent", - "license": "MIT", - "repository": "SamVerschueren/decode-uri-component", - "author": { - "name": "Sam Verschueren", - "email": "sam.verschueren@gmail.com", - "url": "github.com/SamVerschueren" - }, - "engines": { - "node": ">=0.10" - }, - "scripts": { - "test": "xo && nyc ava", - "coveralls": "nyc report --reporter=text-lcov | coveralls" - }, - "files": [ - "index.js" - ], - "keywords": [ - "decode", - "uri", - "component", - "decodeuricomponent", - "components", - "decoder", - "url" - ], - "devDependencies": { - "ava": "^0.17.0", - "coveralls": "^2.13.1", - "nyc": "^10.3.2", - "xo": "^0.16.0" - } + "name": "decode-uri-component", + "version": "0.2.1", + "description": "A better decodeURIComponent", + "license": "MIT", + "repository": "SamVerschueren/decode-uri-component", + "author": { + "name": "Sam Verschueren", + "email": "sam.verschueren@gmail.com", + "url": "github.com/SamVerschueren" + }, + "engines": { + "node": ">=0.10" + }, + "scripts": { + "test": "xo && nyc ava", + "coveralls": "nyc report --reporter=text-lcov | coveralls" + }, + "files": [ + "index.js" + ], + "keywords": [ + "decode", + "uri", + "component", + "decodeuricomponent", + "components", + "decoder", + "url" + ], + "devDependencies": { + "ava": "^0.17.0", + "coveralls": "^2.13.1", + "nyc": "^10.3.2", + "xo": "^0.16.0" + } } diff --git a/readme.md b/readme.md index 795c87f..3ed99b0 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # decode-uri-component -[![Build Status](https://travis-ci.org/SamVerschueren/decode-uri-component.svg?branch=master)](https://travis-ci.org/SamVerschueren/decode-uri-component) [![Coverage Status](https://coveralls.io/repos/SamVerschueren/decode-uri-component/badge.svg?branch=master&service=github)](https://coveralls.io/github/SamVerschueren/decode-uri-component?branch=master) +![CI](https://github.com/SamVerschueren/decode-uri-component/workflows/CI/badge.svg) [![Coverage Status](https://coveralls.io/repos/SamVerschueren/decode-uri-component/badge.svg?branch=master&service=github)](https://coveralls.io/github/SamVerschueren/decode-uri-component?branch=master) > A better [decodeURIComponent](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent) @@ -68,3 +68,16 @@ An encoded component of a Uniform Resource Identifier. ## License MIT © [Sam Verschueren](https://github.com/SamVerschueren) + + +--- + +
+ + Get professional support for this package with a Tidelift subscription + +
+ + Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. +
+
diff --git a/test.js b/test.js index 85adb1d..c083cc6 100644 --- a/test.js +++ b/test.js @@ -32,7 +32,10 @@ const tests = { '%C2x': '\uFFFDx', '%C2%B5': 'µ', '%C2%B5%': 'µ%', - '%%C2%B5%': '%µ%' + '%%C2%B5%': '%µ%', + + // This should actually return `%ea%baZ%ba`, but fixes a DOS attack for now + '%ea%ba%5a%ba': '꺺' }; function macro(t, input, expected) {