From 326d84969190de0fc294e2500329d74560d798c0 Mon Sep 17 00:00:00 2001 From: Feroz Salam Date: Thu, 5 Oct 2023 19:37:24 +0100 Subject: [PATCH] Trim whitespace when processing dids (#1299) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Trim whitespace when processing dids I had some issues when enabling a custom domain using the .well-known file method because of the EOL character – as the code currently stands, any `did` followed by an EOL character is passed for verification as: ``` "responseBody": { "did": "\n" } ``` The presence of the trailing newline character leads to the user receiving the error "The server gave an invalid response and may be out of date". I solved the issue by removing the EOL character from my `did` file, but it would be neater if this was done for the user. Signed-off-by: Feroz Salam * Update did handling based on PR feedback - Read the file in text, strip out non-ASCII chars - Read in the first line of the file and strip any remaining newline characters * identity: don't remove non-ASCII characters simplifies what we are normalizing: just take the first line and strip whitespace, don't try to remove any non-ASCII characters as well. --------- Signed-off-by: Feroz Salam Co-authored-by: bnewbold --- packages/identity/src/handle/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/identity/src/handle/index.ts b/packages/identity/src/handle/index.ts index 8780437efa7..4048f963cd5 100644 --- a/packages/identity/src/handle/index.ts +++ b/packages/identity/src/handle/index.ts @@ -50,7 +50,7 @@ export class HandleResolver { const url = new URL('/.well-known/atproto-did', `https://${handle}`) try { const res = await fetch(url, { signal }) - const did = await res.text() + const did = (await res.text()).split('\n')[0].trim() if (typeof did === 'string' && did.startsWith('did:')) { return did }