diff --git a/.github/workflows/test_and_release.yml b/.github/workflows/test_and_release.yml index 7a26846..3b1df82 100644 --- a/.github/workflows/test_and_release.yml +++ b/.github/workflows/test_and_release.yml @@ -16,10 +16,10 @@ jobs: fail-fast: false matrix: os: [windows-latest, ubuntu-latest, macos-latest] - node: [16, 17, 18] + node: [16, 18] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{matrix.node}} - run: yarn install @@ -30,11 +30,23 @@ jobs: run: yarn run check-types - name: Unit tests run: yarn test - + + tests-chrome: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: lts/* + - run: yarn install + - run: yarn build + - name: Unit tests + run: npx xvfb-maybe yarn test:chrome + maybe-release: name: release runs-on: ubuntu-latest - needs: tests + needs: [tests, tests-chrome] if: github.event_name == 'push' && github.ref == 'refs/heads/master' steps: - uses: google-github-actions/release-please-action@v3 @@ -44,19 +56,19 @@ jobs: package-name: release-please-action bump-minor-pre-major: false changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]' - + - uses: actions/checkout@v3 if: ${{ steps.release.outputs.release_created }} - + - uses: actions/setup-node@v3 with: node-version: 16 registry-url: 'https://registry.npmjs.org' if: ${{ steps.release.outputs.release_created }} - + - run: yarn install if: ${{ steps.release.outputs.release_created }} - + - run: yarn build if: ${{ steps.release.outputs.release_created }} diff --git a/package.json b/package.json index 8a101e3..2f6464b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "build": "tsc -p tsconfig.build.json", "prepublishOnly": "yarn build", "lint": "eslint --color --ext .ts src/ test/ bench/", - "test": "mocha test/**/*.test.ts" + "test": "mocha test/**/*.test.ts", + "test:chrome": "playwright-test --runner mocha test/**/*.test.ts" }, "pre-push": [ "lint" @@ -85,9 +86,9 @@ "karma": "^4.3.0", "mocha": "^10.0.0", "nyc": "^14.1.1", + "playwright-test": "^12.1.1", "prettier": "^2.6.2", "ts-node": "^10.8.1", "typescript": "^4.7.3" - }, - "dependencies": {} + } } diff --git a/src/parse.ts b/src/parse.ts index 7352cf1..de3ff38 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -16,6 +16,10 @@ export function parseIPv4(input: string): Uint8Array | undefined { /** Parse `input` into IPv6 bytes. */ export function parseIPv6(input: string): Uint8Array | undefined { + // strip zone index if it is present + if (input.includes("%")) { + input = input.split("%")[0]; + } if (input.length > MAX_IPV6_LENGTH) { return undefined; } @@ -24,6 +28,10 @@ export function parseIPv6(input: string): Uint8Array | undefined { /** Parse `input` into IPv4 or IPv6 bytes. */ export function parseIP(input: string): Uint8Array | undefined { + // strip zone index if it is present + if (input.includes("%")) { + input = input.split("%")[0]; + } if (input.length > MAX_IPV6_LENGTH) { return undefined; } diff --git a/test/index.test.ts b/test/index.test.ts index acd541c..e36fc00 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -64,6 +64,11 @@ const validIPv6 = [ input: "abcd:0:1:2:3:4:5:6", output: Uint8Array.from([0xab, 0xcd, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6]), }, + { + // IPv6 with a zone index - https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses_(with_zone_index) + input: "fe80::8cb1:25ff:fec5:28e3%llw0", + output: Uint8Array.from([0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0x8c, 0xb1, 0x25, 0xff, 0xfe, 0xc5, 0x28, 0xe3]), + }, ]; const invalidIPv6 = [