Skip to content

Commit 1c82f72

Browse files
committed
improve tag parsing
1 parent 2eae336 commit 1c82f72

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

apps/webapp/app/v3/getDeploymentImageRef.server.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,34 @@ export function isEcrRegistry(registryHost: string) {
158158
}
159159

160160
function parseRegistryTags(tags: string): Tag[] {
161-
return tags.split(",").map((tag) => {
162-
const [key, value] = tag.split("=");
163-
return { Key: key, Value: value };
164-
});
161+
if (!tags) {
162+
return [];
163+
}
164+
165+
return tags
166+
.split(",")
167+
.map((t) => {
168+
const tag = t.trim();
169+
if (tag.length === 0) {
170+
return null;
171+
}
172+
173+
// If there's no '=' in the tag, treat the whole tag as the key with an empty value
174+
const equalIndex = tag.indexOf("=");
175+
const key = equalIndex === -1 ? tag : tag.slice(0, equalIndex);
176+
const value = equalIndex === -1 ? "" : tag.slice(equalIndex + 1);
177+
178+
if (key.trim().length === 0) {
179+
logger.warn("Invalid ECR tag format (empty key), skipping tag", { tag: t });
180+
return null;
181+
}
182+
183+
return {
184+
Key: key.trim(),
185+
Value: value.trim(),
186+
} as Tag;
187+
})
188+
.filter((tag): tag is Tag => tag !== null);
165189
}
166190

167191
async function createEcrRepository({

0 commit comments

Comments
 (0)