From 306e19b0910f54c20bac32ffa518aac2d70841f1 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:03:29 -0800 Subject: [PATCH] fix: dnsLinkLabel decode encode (#34) * fix: dnsLinkLabel decode encode * chore: update github workflows * chore: ensure test runs during CI --- .github/dependabot.yml | 17 +++ .github/pull_request_template.md | 29 ++++ .github/workflows/automerge.yml | 8 + .github/workflows/main.yml | 157 ++++++++++++++++++++ .github/workflows/semantic-pull-request.yml | 12 ++ .github/workflows/stale.yml | 13 ++ .github/workflows/sync.yml | 19 --- package.json | 2 +- src/lib/dns-link-labels.ts | 4 +- tests/dns-link-labels.spec.ts | 21 +++ 10 files changed, 260 insertions(+), 22 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/automerge.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/semantic-pull-request.yml create mode 100644 .github/workflows/stale.yml delete mode 100644 .github/workflows/sync.yml create mode 100644 tests/dns-link-labels.spec.ts diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..27d304fc --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + time: "10:00" + open-pull-requests-limit: 20 + commit-message: + prefix: "deps" + prefix-development: "deps(dev)" +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: ci diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..f8966ba9 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,29 @@ +## Title + + + +## Description + + + +## Notes & open questions + + + +## Change checklist + +- [ ] I have performed a self-review of my own code +- [ ] I have made corresponding changes to the documentation if necessary (this includes comments as well) +- [ ] I have added tests that prove my fix is effective or that my feature works diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 00000000..d57c2a02 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,8 @@ +name: Automerge +on: [ pull_request ] + +jobs: + automerge: + uses: protocol/.github/.github/workflows/automerge.yml@master + with: + job: 'automerge' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..eed1e99b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,157 @@ +name: CI +on: + push: + branches: + - main + pull_request: + branches: + - '**' + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + + check: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present lint + - run: npm run --if-present dep-check + - run: npm run --if-present doc-check + + test-node: + needs: build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + node: [lts/*] + fail-fast: true + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:node + - uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 + with: + flags: node + files: .coverage/*,packages/*/.coverage/* + + test-chrome: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome + - uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 + with: + flags: chrome + files: .coverage/*,packages/*/.coverage/* + + test-chrome-webworker: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:chrome-webworker + - uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 + with: + flags: chrome-webworker + files: .coverage/*,packages/*/.coverage/* + + test-firefox: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox + - uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 + with: + flags: firefox + files: .coverage/*,packages/*/.coverage/* + + test-firefox-webworker: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:firefox-webworker + - uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 + with: + flags: firefox-webworker + files: .coverage/*,packages/*/.coverage/* + + test-webkit: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npm run --if-present test:webkit + - uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 + with: + flags: webkit + files: .coverage/*,packages/*/.coverage/* + + test-electron-main: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx xvfb-maybe npm run --if-present test:electron-main + - uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 + with: + flags: electron-main + files: .coverage/*,packages/*/.coverage/* + + test-electron-renderer: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - uses: ipfs/aegir/actions/cache-node-modules@master + - run: npx xvfb-maybe npm run --if-present test:electron-renderer + - uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 + with: + flags: electron-renderer + files: .coverage/*,packages/*/.coverage/* diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml new file mode 100644 index 00000000..bd00f090 --- /dev/null +++ b/.github/workflows/semantic-pull-request.yml @@ -0,0 +1,12 @@ +name: Semantic PR + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + main: + uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 00000000..16d65d72 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,13 @@ +name: Close and mark stale issue + +on: + schedule: + - cron: '0 0 * * *' + +permissions: + issues: write + pull-requests: write + +jobs: + stale: + uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3 diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml deleted file mode 100644 index 3f8b7446..00000000 --- a/.github/workflows/sync.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: pull - -on: - workflow_dispatch - -jobs: - sync: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Pull from another repository - uses: ipfs-examples/actions-pull-directory-from-repo@main - with: - source-repo: ipfs-examples/helia-examples - source-folder-path: examples/${{ github.event.repository.name }} - source-branch: main - target-branch: main - git-username: github-actions - git-email: github-actions@github.com diff --git a/package.json b/package.json index 39aa1ac9..93ce0604 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "serve": "webpack serve --mode=development", "serve:prod": "webpack serve --mode=production", "start": "npm run serve", - "test": "webpack --env test && npx mocha dist/tests.js", + "test:node": "webpack --env test && npx mocha dist/tests.js", "postinstall": "patch-package" }, "browser": "./dist/src/index.js", diff --git a/src/lib/dns-link-labels.ts b/src/lib/dns-link-labels.ts index 55666b85..04aabe40 100644 --- a/src/lib/dns-link-labels.ts +++ b/src/lib/dns-link-labels.ts @@ -18,7 +18,7 @@ export function isDnsLabel (label: string): boolean { * @example en-wikipedia--on--ipfs-org.ipns.example.net -> example.net/ipns/en.wikipedia-on-ipfs.org */ export function dnsLinkLabelDecoder (linkLabel: string): string { - return linkLabel.replace(/--/g, '-').replace(/-/g, '.') + return linkLabel.replace(/--/g, '%').replace(/-/g, '.').replace(/%/g, '-') } /** @@ -29,5 +29,5 @@ export function dnsLinkLabelDecoder (linkLabel: string): string { * @example example.net/ipns/en.wikipedia-on-ipfs.org → Host: en-wikipedia--on--ipfs-org.ipns.example.net */ export function dnsLinkLabelEncoder (linkLabel: string): string { - return linkLabel.replace(/\./g, '-').replace(/-/g, '--') + return linkLabel.replace(/-/g, '--').replace(/\./g, '-') } diff --git a/tests/dns-link-labels.spec.ts b/tests/dns-link-labels.spec.ts new file mode 100644 index 00000000..1fafbb69 --- /dev/null +++ b/tests/dns-link-labels.spec.ts @@ -0,0 +1,21 @@ +/* eslint-env mocha */ +import { expect } from 'aegir/chai' +import { dnsLinkLabelDecoder, dnsLinkLabelEncoder } from '../src/lib/dns-link-labels.ts' + +describe('dns-link-labels', () => { + it('should support specs-ipfs-tech', () => { + const actualDomainName = 'specs.ipfs.tech' + const encodedLabel = dnsLinkLabelEncoder(actualDomainName) + expect(encodedLabel).to.equal('specs-ipfs-tech') + const result = dnsLinkLabelDecoder(encodedLabel) + expect(result).to.equal(actualDomainName) + }) + + it('should support en.wikipedia-on-ipfs.org', () => { + const actualDomainName = 'en.wikipedia-on-ipfs.org' + const encodedLabel = dnsLinkLabelEncoder(actualDomainName) + expect(encodedLabel).to.equal('en-wikipedia--on--ipfs-org') + const result = dnsLinkLabelDecoder(encodedLabel) + expect(result).to.equal(actualDomainName) + }) +})