Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Fix HTML creator crediting incorrect image tags (#4653)

zackb96fc34991f6
diff --git a/frontend/src/utils/attribution-html.ts b/frontend/src/utils/attribution-html.ts
index 714f653a7..f9412569d 100644
--- a/frontend/src/utils/attribution-html.ts
+++ b/frontend/src/utils/attribution-html.ts
@@ -46,9 +46,31 @@ const h = (
attrs: Record<string, string>,
children: string[] | null = null
): string => {
+ const selfClosingTags = [
+ "area",
+ "base",
+ "br",
+ "col",
+ "embed",
+ "hr",
+ "img",
+ "input",
+ "link",
+ "meta",
+ "param",
+ "source",
+ "track",
+ "wbr",
+ ]
+
const map = Object.entries(attrs)
.map(([key, value]) => `${key}="${value}"`)
.join(" ")
+
+ if (selfClosingTags.includes(name)) {
+ return map ? `<${name} ${map} />` : `<${name} />`
+ }
+
const opening = map ? `<${name} ${map}>` : `<${name}>`
const closing = `</${name}>`
return `${opening}${(children ?? []).join("\n")}${closing}`