Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markup is breaking due to HTML entities generated in the alt text #34

Closed
CjRootStudio opened this issue Aug 12, 2024 · 2 comments · Fixed by #36
Closed

Markup is breaking due to HTML entities generated in the alt text #34

CjRootStudio opened this issue Aug 12, 2024 · 2 comments · Fixed by #36
Assignees

Comments

@CjRootStudio
Copy link

Responses from GPT sometimes includes words or phrases surrounded by quote marks (or other HTML special characters/entities). This is causing issues where the generated alt text breaks the HTML markup.

Example

<img src="example.jpg" alt="Stacked coins of increasing height next to wooden blocks spelling "HEALTH." The arrangement symbolizes the connection between health and wealth.">

Notice how HEALTH is surrounded by quote marks. This is breaking the markup and causing multiple knock-on effects.

Suggested Fix

Could the returned response be further sanitised to escape special characters? There are cases where they might be relevant to the description so removing them entirely wouldn't be ideal. For example:

$result = trim($response->choices[0]->message->content);

// Escape the special characters
$sanitisedResult = htmlspecialchars($result, ENT_QUOTES, 'UTF-8');

Environment

Statamic: 4.58.2
PHP: 8.2.17
A.I.D.A: 1.0.1

@Sm1lEE Sm1lEE self-assigned this Aug 13, 2024
@Sm1lEE Sm1lEE linked a pull request Aug 13, 2024 that will close this issue
@Sm1lEE
Copy link
Collaborator

Sm1lEE commented Aug 13, 2024

Hi @CjRootStudio ,

thanks for your report. We included your suggested fix in the newest version and also provided an alternative solution for custom generators using Statamic's sanitize modifier.

@CjRootStudio
Copy link
Author

Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants