Skip to content

Commit

Permalink
fix: dnsLinkLabel decode encode (#34)
Browse files Browse the repository at this point in the history
* fix: dnsLinkLabel decode encode

* chore: update github workflows

* chore: ensure test runs during CI
  • Loading branch information
SgtPooki committed Feb 24, 2024
1 parent 674c69f commit 306e19b
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 22 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Title

<!---
The title of the PR will be the commit message of the merge commit, so please make sure it is descriptive enough.
We utilize the Conventional Commits specification for our commit messages. See <https://www.conventionalcommits.org/en/v1.0.0/#specification> for more information.
The commit tag types can be of one of the following: feat, fix, deps, refactor, chore, docs. See <https://github.com/ipfs/helia/blob/main/.github/workflows/main.yml#L184-L192>
The title must also be fewer than 72 characters long or it will fail the Semantic PR check. See <https://github.com/ipfs/helia/blob/main/.github/workflows/semantic-pull-request.yml>
--->

## Description

<!--
Please write a summary of your changes and why you made them.
Please include any relevant issues in here, for example:
Related https://github.com/ipfs/helia/issues/ABCD.
Fixes https://github.com/ipfs/helia/issues/XYZ.
-->

## Notes & open questions

<!--
Any notes, remarks or open questions you have to make about the PR which don't need to go into the final commit message.
-->

## 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
8 changes: 8 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Automerge
on: [ pull_request ]

jobs:
automerge:
uses: protocol/.github/.github/workflows/automerge.yml@master
with:
job: 'automerge'
157 changes: 157 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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/*
12 changes: 12 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 0 additions & 19 deletions .github/workflows/sync.yml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/dns-link-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '-')
}

/**
Expand All @@ -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, '-')
}
21 changes: 21 additions & 0 deletions tests/dns-link-labels.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 306e19b

Please sign in to comment.