From e23fedb8a9d939ea9c370079a9d0adc91e11f1a8 Mon Sep 17 00:00:00 2001 From: bourgeoa Date: Thu, 23 Jan 2025 22:52:44 +0100 Subject: [PATCH 1/2] do not check MetaRanges on container --- src/storage/conversion/ConstantConverter.ts | 6 ++++-- test/unit/storage/conversion/ConstantConverter.test.ts | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/storage/conversion/ConstantConverter.ts b/src/storage/conversion/ConstantConverter.ts index a19cce4bef..fa7a8d7af1 100644 --- a/src/storage/conversion/ConstantConverter.ts +++ b/src/storage/conversion/ConstantConverter.ts @@ -110,10 +110,12 @@ export class ConstantConverter extends RepresentationConverter { } // Only replace the representation if it matches the media range settings - if (!this.options.enabledMediaRanges.some((type): boolean => matchesMediaType(sourceContentType, type))) { + if (!isContainer && + !this.options.enabledMediaRanges.some((type): boolean => matchesMediaType(sourceContentType, type))) { throw new NotImplementedHttpError(`${sourceContentType} is not one of the enabled media types.`); } - if (this.options.disabledMediaRanges.some((type): boolean => matchesMediaType(sourceContentType, type))) { + if (!isContainer && + this.options.disabledMediaRanges.some((type): boolean => matchesMediaType(sourceContentType, type))) { throw new NotImplementedHttpError(`${sourceContentType} is one of the disabled media types.`); } } diff --git a/test/unit/storage/conversion/ConstantConverter.test.ts b/test/unit/storage/conversion/ConstantConverter.test.ts index d6d27d66fd..b7fb027b24 100644 --- a/test/unit/storage/conversion/ConstantConverter.test.ts +++ b/test/unit/storage/conversion/ConstantConverter.test.ts @@ -76,9 +76,9 @@ describe('A ConstantConverter', (): void => { it('does not support representations if their content-type is not enabled.', async(): Promise => { const preferences = { type: { 'text/html': 1 }}; const representation = { metadata: new RepresentationMetadata({ [CONTENT_TYPE]: 'text/plain' }) } as any; - const args = { identifier: { path: 'container/' }, representation, preferences }; + const args = { identifier, representation, preferences }; - converter = new ConstantConverter('abc/def/index.html', 'text/html', { enabledMediaRanges: [ 'text/turtle' ]}); + converter = new ConstantConverter('abc/def/test.html', 'text/html', { enabledMediaRanges: [ 'text/turtle' ]}); await expect(converter.canHandle(args)).rejects.toThrow('text/plain is not one of the enabled media types.'); }); @@ -86,7 +86,7 @@ describe('A ConstantConverter', (): void => { it('does not support representations if their content-type is disabled.', async(): Promise => { const preferences = { type: { 'text/html': 1 }}; const representation = { metadata: new RepresentationMetadata({ [CONTENT_TYPE]: 'text/plain' }) } as any; - const args = { identifier: { path: 'container/' }, representation, preferences }; + const args = { identifier, representation, preferences }; converter = new ConstantConverter('abc/def/index.html', 'text/html', { disabledMediaRanges: [ 'text/*' ]}); From e1e69101417d1d08f22cd9eaa0d5b3a460c7e93b Mon Sep 17 00:00:00 2001 From: bourgeoa Date: Thu, 23 Jan 2025 23:13:10 +0100 Subject: [PATCH 2/2] undo test.html --- test/unit/storage/conversion/ConstantConverter.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/storage/conversion/ConstantConverter.test.ts b/test/unit/storage/conversion/ConstantConverter.test.ts index b7fb027b24..d6d322dfeb 100644 --- a/test/unit/storage/conversion/ConstantConverter.test.ts +++ b/test/unit/storage/conversion/ConstantConverter.test.ts @@ -78,7 +78,7 @@ describe('A ConstantConverter', (): void => { const representation = { metadata: new RepresentationMetadata({ [CONTENT_TYPE]: 'text/plain' }) } as any; const args = { identifier, representation, preferences }; - converter = new ConstantConverter('abc/def/test.html', 'text/html', { enabledMediaRanges: [ 'text/turtle' ]}); + converter = new ConstantConverter('abc/def/index.html', 'text/html', { enabledMediaRanges: [ 'text/turtle' ]}); await expect(converter.canHandle(args)).rejects.toThrow('text/plain is not one of the enabled media types.'); });