diff --git a/.changeset/old-ladybugs-sing.md b/.changeset/old-ladybugs-sing.md new file mode 100644 index 0000000..742e0a3 --- /dev/null +++ b/.changeset/old-ladybugs-sing.md @@ -0,0 +1,14 @@ +--- +'@difizen/mana-common': patch +'@difizen/mana-docs': patch +'@difizen/mana-app': patch +'@difizen/mana-core': patch +'@difizen/mana-l10n': patch +'@difizen/mana-observable': patch +'@difizen/mana-react': patch +'@difizen/mana-syringe': patch +'@difizen/mana-ui': patch +'@difizen/umi-plugin-mana': patch +--- + +fix: support query parse in uri diff --git a/packages/mana-common/src/uri.spec.ts b/packages/mana-common/src/uri.spec.ts index a429c48..6d03c9a 100644 --- a/packages/mana-common/src/uri.spec.ts +++ b/packages/mana-common/src/uri.spec.ts @@ -28,6 +28,23 @@ describe('URI', () => { new URI('file:///a/b/c/example.png?KeyId=asgxdjasbcxjsc').toString() === 'file:///a/b/c/example.png?KeyId=asgxdjasbcxjsc', ); + assert( + new URI('file:///a/b/c/example.png?KeyId=asgxdjasbcxjsc', { + simpleMode: false, + }).query === 'KeyId=asgxdjasbcxjsc', + ); + assert( + new URI('file:///a/b/c/example.png?KeyId=asgxdjasbcxjsc', { + simpleMode: false, + }).getParsedQuery()['KeyId'] === 'asgxdjasbcxjsc', + ); + assert( + new URI('file:///a/b/c/example.png?KeyId=asgxdjasbcxjsc').toString() === + URI.withQuery( + new URI('file:///a/b/c/example.png'), + URI.stringifyQuery({ KeyId: 'asgxdjasbcxjsc' }), + ).toString(), + ); assert( VscodeURI.parse('file:///a/b/c/example.png?KeyId=asgxdjasbcxjsc', false, { simpleMode: false, diff --git a/packages/mana-common/src/uri.ts b/packages/mana-common/src/uri.ts index 9296611..bf1cbdb 100644 --- a/packages/mana-common/src/uri.ts +++ b/packages/mana-common/src/uri.ts @@ -181,4 +181,28 @@ export class URI { } return !!Path.relative(left, right); } + + getParsedQuery(): { [key: string]: string } { + const queryString = this.query; + const query: Record = {}; + const pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split( + '&', + ); + for (let i = 0; i < pairs.length; i++) { + const pair = pairs[i].split('='); + query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); + } + return query; + } + + static stringifyQuery(query: { [key: string]: any }): string { + const values: string[] = []; + Object.keys(query).forEach((key) => { + const value = encodeURIComponent(query[key]); + if (value !== undefined) { + values.push(encodeURIComponent(key) + '=' + value); + } + }); + return values.join('&'); + } }