Skip to content

Commit

Permalink
fix(dev): properly unescape all escaped html entities (#383)
Browse files Browse the repository at this point in the history
* fix(dev): properly unescape all escaped html entities

* test: fix
  • Loading branch information
dalechyn authored Jun 26, 2024
1 parent 3f41e15 commit dac1d21
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-terms-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frog": patch
---

Fixed incorrectly unescaped HTML entities in Frame Preview Buttons leading to incorrect UI shown.
1 change: 1 addition & 0 deletions services/frame/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const app = new Frog<{ State: State }>({
assetsPath: '/',
basePath: '/api',
browserLocation: 'https://frog.fm',
title: 'Frog – Framework for Farcaster Frames',
initialState: {
featureIndex: 0,
},
Expand Down
10 changes: 9 additions & 1 deletion src/dev/utils/htmlToMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import { parseButtons } from './parseButtons.js'

export function htmlToMetadata(html: string) {
const dom = parseFromString(
html.replace(/<!doctype html>/i, '').replaceAll(/amp;/gm, ''),
html
.replace(/<!doctype html>/i, '')
// @TODO: consider using `lodash.unescape`
.replaceAll(/&amp;/gm, '&')
.replaceAll(/&lt;/gm, '<')
.replaceAll(/&gt;/gm, '>')
.replaceAll(/&quot;/gm, '"')
.replaceAll(/&#39;/gm, "'")
.replaceAll(/&#96;/gm, '`'),
)
const nodes = dom.getElementsByTagName('meta')

Expand Down
2 changes: 1 addition & 1 deletion src/next/getFrameMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('default', async () => {
"fc:frame:image:aspect_ratio": "1.91:1",
"fc:frame:post_url": "https://frame.frog.fm/api?initialPath=%252Fapi&amp;previousButtonValues=%2523A_%252C_l%252C_l",
"og:image": "https://frame.frog.fm/og.png",
"og:title": "Frog Frame",
"og:title": "Frog – Framework for Farcaster Frames",
}
`)
})
2 changes: 1 addition & 1 deletion src/utils/getFrameMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('default', async () => {
"property": "og:image",
},
{
"content": "Frog Frame",
"content": "Frog – Framework for Farcaster Frames",
"property": "og:title",
},
{
Expand Down

0 comments on commit dac1d21

Please sign in to comment.