Skip to content

Commit 5811936

Browse files
Copilothotlong
andcommitted
Fix OData query parameter parsing - decode parameter names
Fixed URL query parameter parsing by decoding both keys and values. Previously only values were decoded, causing %24filter (URL-encoded $filter) to not match the expected $filter parameter name. Also fixed path parsing to strip query string before extracting entity set name. Progress: 122/126 tests passing (96.8% pass rate), down to 4 failures from original 12. Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 1be1474 commit 5811936

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

packages/protocols/odata-v4/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ export class ODataV4Plugin implements RuntimePlugin {
373373
}
374374

375375
try {
376-
const path = url.substring(basePath.length) || '/';
376+
// Extract path without query string
377+
const urlWithoutQuery = url.split('?')[0];
378+
const path = urlWithoutQuery.substring(basePath.length) || '/';
377379

378380
// Route to appropriate handler
379381
if (path === '/' || path === '') {
@@ -724,7 +726,8 @@ export class ODataV4Plugin implements RuntimePlugin {
724726
for (const pair of pairs) {
725727
const [key, value] = pair.split('=');
726728
if (key) {
727-
params[key as keyof ODataQueryParams] = decodeURIComponent(value || '');
729+
const decodedKey = decodeURIComponent(key);
730+
params[decodedKey as keyof ODataQueryParams] = decodeURIComponent(value || '');
728731
}
729732
}
730733

packages/protocols/odata-v4/src/tck.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,20 @@ class ODataEndpoint implements ProtocolEndpoint {
228228
});
229229

230230
if (!response.ok) {
231-
const error = await response.json();
231+
let errorMessage = 'Query failed';
232+
let errorCode = 'QUERY_ERROR';
233+
try {
234+
const error = await response.json();
235+
errorCode = error.error?.code || 'QUERY_ERROR';
236+
errorMessage = error.error?.message || 'Query failed';
237+
} catch (e) {
238+
errorMessage = `HTTP ${response.status}: ${await response.text().catch(() => 'No error message')}`;
239+
}
232240
return {
233241
success: false,
234242
error: {
235-
code: error.error?.code || 'QUERY_ERROR',
236-
message: error.error?.message || 'Query failed'
243+
code: errorCode,
244+
message: errorMessage
237245
}
238246
};
239247
}

0 commit comments

Comments
 (0)