React 错误 html 转义属性名称中的引号

React mistakenly html escapes quotes in attribute names

我有一个 Next.js / (SSR React) 应用程序。我正在通过道具将 属性 传递到元组件中。获取字符串的标签如下所示:

 <meta property="og:description" content={ `${description}` } />

放入其中的内容如下所示:"This is a quote" - Quotes" 来自 javascript 字符串。结果如下所示:&quot;This is a quote &quot;。我正在寻找的是传递到元标记中的字符串,而不是转义双引号。这是怎么回事,我该如何解决?

PS:我尝试使用 unicode 字符,将描述放在字符串文字之外,然后用 let q = String.chartocode(38) 之类的东西添加 q 代替双引号。所有人都有相同的结果。

这是正确的转义,因为 <meta property="og:description" content=""This is a quote" - Quotes" /> 无效 html。双引号需要转义。

此外,OpenGraph 确实支持属性中的 html 个实体,因此 &quot;This is a quote&quot; - Quotes 在 OpenGraph 解析视图中应显示为 "This is a quote" - Quotes