8000 fix(artifacts): encode filenames in artifact request URLs by Aaravkhanal · Pull Request #560 · google/adk-web · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/app/core/services/artifact.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@ describe('ArtifactService', () => {
expect(service).toBeTruthy();
});

for (const [artifactName, encodedName] of [
['report#1.json', 'report%231.json'],
['report?draft.json', 'report%3Fdraft.json'],
['100%.txt', '100%25.txt'],
['report%23.json', 'report%2523.json'],
['user:reports/summary.json', 'user%3Areports%2Fsummary.json'],
['résumé final.json', 'r%C3%A9sum%C3%A9%20final.json'],
]) {
it(`should preserve reserved characters in latest artifact ${artifactName}`, () => {
service.getLatestArtifact(USER_ID, APP_NAME, SESSION_ID, artifactName)
.subscribe();
const req = httpTestingController.expectOne(
API_SERVER_BASE_URL +
`/apps/${APP_NAME}/users/${USER_ID}/sessions/${SESSION_ID}/artifacts/${
encodedName}`);
expect(req.request.method).toBe('GET');
req.flush({});
});

it(`should preserve reserved characters in versioned artifact ${artifactName}`, () => {
service.getArtifactVersion(
USER_ID, APP_NAME, SESSION_ID, artifactName, ARTIFACT_VERSION)
.subscribe();
const req = httpTestingController.expectOne(
API_SERVER_BASE_URL +
`/apps/${APP_NAME}/users/${USER_ID}/sessions/${SESSION_ID}/artifacts/${
encodedName}/versions/${ARTIFACT_VERSION}`);
expect(req.request.method).toBe('GET');
req.flush({});
});
}

describe('getLatestArtifact', () => {
it('should call the correct endpoint to get latest artifact', () => {
service.getLatestArtifact(USER_ID, APP_NAME, SESSION_ID, ARTIFACT_ID)
Expand Down
4 changes: 2 additions A83C & 2 deletions src/app/core/services/artifact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ArtifactService implements ArtifactServiceInterface {
) {
const url =
this.apiServerDomain +
`/apps/${appName}/users/${userId}/sessions/${sessionId}/artifacts/${artifactName}`;
`/apps/${appName}/users/${userId}/sessions/${sessionId}/artifacts/${encodeURIComponent(artifactName)}`;

return this.http.get<any>(url);
}
Expand All @@ -49,7 +49,7 @@ export class ArtifactService implements ArtifactServiceInterface {
) {
const url =
this.apiServerDomain +
`/apps/${appName}/users/${userId}/sessions/${sessionId}/artifacts/${artifactName}/versions/${versionId}`;
`/apps/${appName}/users/${userId}/sessions/${sessionId}/artifacts/${encodeURIComponent(artifactName)}/versions/${versionId}`;

return this.http.get<any>(url);
}
Expand Down
Loading
0