Skip to content

Commit 4a47315

Browse files
fix(body-data): detect YAML with /x-yaml content type (#1171)
fixes #1170
1 parent 28ceb3b commit 4a47315

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

packages/helix-shared-body-data/src/body-data-wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async function getData(request, opts) {
3232
}
3333

3434
const { supportYAML } = opts;
35-
if (supportYAML && /\/yaml/.test(contentType) && BODY_METHODS.includes(request.method)) {
35+
if (supportYAML && /\/(x-)?yaml/.test(contentType) && BODY_METHODS.includes(request.method)) {
3636
return request.text();
3737
}
3838

packages/helix-shared-body-data/test/body-data-wrapper.test.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -273,24 +273,26 @@ describe('Body Data Wrapper Unit Tests (YAML Body)', () => {
273273
const contents = { indices: [] };
274274

275275
['POST', 'post', 'PUT', 'PATCH'].forEach((method) => {
276-
it(`Loads YAML (${method})`, async () => {
277-
const universalfunct = async (request, context) => {
278-
const yaml = YAML.parse(context.data);
279-
assert.deepStrictEqual(yaml, contents);
280-
return new Response('ok');
281-
};
282-
283-
const actualfunct = wrap(universalfunct).with(bodyData, { supportYAML: true });
284-
const response = await actualfunct(new Request('http://localhost', {
285-
body: YAML.stringify(contents),
286-
method,
287-
headers: {
288-
'content-type': 'text/yaml',
289-
},
290-
}), {
291-
log,
276+
['text/yaml', 'application/x-yaml'].forEach((yamlType) => {
277+
it(`Loads YAML with type ${yamlType} (${method})`, async () => {
278+
const universalfunct = async (request, context) => {
279+
const yaml = YAML.parse(context.data);
280+
assert.deepStrictEqual(yaml, contents);
281+
return new Response('ok');
282+
};
283+
284+
const actualfunct = wrap(universalfunct).with(bodyData, { supportYAML: true });
285+
const response = await actualfunct(new Request('http://localhost', {
286+
body: YAML.stringify(contents),
287+
method,
288+
headers: {
289+
'content-type': yamlType,
290+
},
291+
}), {
292+
log,
293+
});
294+
assert.strictEqual(response.status, 200, 'universal function should be executed');
292295
});
293-
assert.strictEqual(response.status, 200, 'universal function should be executed');
294296
});
295297
});
296298

0 commit comments

Comments
 (0)