Skip to content

Commit

Permalink
fix: URI resolution issue - avoid ambiguities
Browse files Browse the repository at this point in the history
  • Loading branch information
ohager committed Sep 7, 2023
1 parent 4a66ce4 commit 612c0a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 4 additions & 12 deletions packages/standards/src/src47/URIResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,11 @@ export class URIResolver {
*/
public static convertKnownTldUri(uri: string): string {
uri = uri.toLowerCase();
for (const knownTld of KnownTlds) {
const index = uri.lastIndexOf('.' + knownTld);
if (index > -1) {
const pathIndex = uri.indexOf('/', index);
const path = pathIndex > -1 ? uri.substring(pathIndex) : '';
uri = uri.slice(0, index) + `@${knownTld}`;
if(path){
uri += path;
}
break;
}
const expression = `\\.(${KnownTlds.join('|')})(/[a-zA-Z0-9_-]+)?$`;
const matches = new RegExp(expression).exec(uri);
if (matches) {
return uri.substring(0, matches.index) + '@' + uri.substring(matches.index + 1);
}

return uri;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/standards/src/src47/__tests__/URIResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ describe('URIResolver', () => {
expect(convertedUri).toEqual('http://example@com');
});

it('should consider only extact TLDs', () => {
const uri = 'http://ohager.nfts.signum';
const convertedUri = URIResolver.convertKnownTldUri(uri);
expect(convertedUri).toEqual('http://ohager.nfts@signum');
});

it('should handle append further (deep) field paths - domain only', () => {
for (const tld of KnownTlds) {
const uri = `https://domain.${tld}/ac`;
Expand Down

0 comments on commit 612c0a9

Please sign in to comment.