Skip to content

Commit

Permalink
fix: bug where did:mailto with pct-encoded email parts was not decode…
Browse files Browse the repository at this point in the history
…d correctly (#719)

… right, causing access/authorize not to send emails for email addresses
with '+'

Motivation:
* storacha/w3cli#73
  • Loading branch information
gobengo authored Mar 31, 2023
1 parent 6bc4dc3 commit c367639
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/access-api/src/utils/did-mailto.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export function toEmail(did) {
if (parts[1] !== 'mailto') {
throw new Error(`DID ${did} is not a mailto did.`)
}
return `${parts[3]}@${parts[2]}`
return `${decodeURIComponent(parts[3])}@${decodeURIComponent(parts[2])}`
}
7 changes: 5 additions & 2 deletions packages/access-api/test/access-client-agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ for (const accessApiVariant of /** @type {const} */ ([
}
const spaceWithStorageProvider = principal.ed25519.generate()
async function createContext() {
/** @type {{url:string}[]} */
/** @type {{url:string,to:string}[]} */
const emails = []
const email = createEmail(emails)
const ctx = await context({
Expand Down Expand Up @@ -384,7 +384,7 @@ for (const accessApiVariant of /** @type {const} */ ([
const abort = new AbortController()
after(() => abort.abort())
const account = {
email: /** @type {const} */ ('[email protected]'),
email: /** @type {const} */ ('example+123@dag.house'),
did: thisEmailDidMailto,
}
const { connection, emails } = await accessApiVariant.create()
Expand All @@ -409,6 +409,9 @@ for (const accessApiVariant of /** @type {const} */ ([
with: space.did,
})
assertNotError(spaceInfoResult)

const latestEmail = emails.at(-1)
assert.deepEqual(latestEmail?.to, account.email, 'emails are equal')
})

it('authorizeWithPollClaim', async () => {
Expand Down

0 comments on commit c367639

Please sign in to comment.