[ICU-15403] Trim whitespace on storage buckets and host sets json attrs serializers (#2636)

* trim whitespace on json attrs in storage bucket serializer

* add test for storage bucket serializer

* move trimWhitespace check to application level

* add trimWhitespace to preferred_endpoints attr

* add conditional for string arr

* trim whitespace on str arr

* add check for null val

* refactor, move logic

* relocate comment

* add unit test for application serializer
This commit is contained in:
Lauren authored and GitHub committed 2025-02-11 18:31:01 -05:00
1 parent b287683a61
commit e8cc22879f
7 files changed
+46 -5

No files matched your search

@@ -88,6 +88,7 @@ export default class GeneratedHostSetModel extends BaseModel {
name: ['aws', 'azure', 'gcp'],
},
emptyArrayIfMissing: true,
trimWhitespace: true,
})
preferred_endpoints;
@@ -70,6 +70,7 @@ export default class GeneratedStorageBucketModel extends BaseModel {
@attr('string', {
isNestedAttribute: true,
description: 'The AWS region to use.',
trimWhitespace: true,
})
region;
@@ -109,6 +110,7 @@ export default class GeneratedStorageBucketModel extends BaseModel {
@attr('string', {
isNestedAttribute: true,
description: 'The role ARN to use.',
trimWhitespace: true,
})
role_arn;
@@ -60,6 +60,18 @@ export default class ApplicationSerializer extends RESTSerializer {
// Do not serialize `disabled` fields.
// TODO: disabled is temporarily disabled
if (key === 'disabled') delete json[key];
// Before we transform our json
// Let's trim the values in the json obj
// Currently, json values will only ever be a string or an array
if (options.trimWhitespace && json[key]) {
if (typeOf(json[key]) === 'array') {
json[key] = json[key].map((str) => str.trim());
} else if (typeOf(json[key] === 'string')) {
json[key] = json[key].trim();
}
}
// Push nested attributes down into the attributes key
if (options.isNestedAttribute && json[key] !== undefined) {
if (!json.attributes) json.attributes = {};
@@ -72,6 +72,7 @@ export default class StorageBucketSerializer extends ApplicationSerializer {
const value = super.serializeAttribute(...arguments);
const { credentialType } = snapshot.record;
const { options } = attribute;
// This deletes any fields that don't belong to the record's credential type
if (options.isNestedAttribute && json.attributes) {
// The key must be included in the fieldsByType list above