diff --git a/app/Controllers/EpisodeController.php b/app/Controllers/EpisodeController.php index b4c57449..f2642152 100644 --- a/app/Controllers/EpisodeController.php +++ b/app/Controllers/EpisodeController.php @@ -235,7 +235,7 @@ class EpisodeController extends BaseController $oembed->addChild('thumbnail_height', (string) config('Images')->podcastCoverSizes['og']['height']); $oembed->addChild( 'html', - htmlentities( + htmlspecialchars( '', diff --git a/app/Helpers/form_helper.php b/app/Helpers/form_helper.php index aedc6db3..bddd4365 100644 --- a/app/Helpers/form_helper.php +++ b/app/Helpers/form_helper.php @@ -43,3 +43,46 @@ if (! function_exists('form_markdown_textarea')) { . "\n"; } } + + +if (! function_exists('parse_form_attributes')) { + /** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @param array|string $attributes List of attributes + * @param array $default Default values + */ + function parse_form_attributes(array|string $attributes, array $default): string + { + if (is_array($attributes)) { + foreach (array_keys($default) as $key) { + if (isset($attributes[$key])) { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } + } + + if (! empty($attributes)) { + $default = array_merge($default, $attributes); + } + } + + $att = ''; + + foreach ($default as $key => $val) { + if (! is_bool($val)) { + if ($key === 'name' && ! strlen($default['name'])) { + continue; + } + + $att .= $key . '="' . $val . '"' . ($key === array_key_last($default) ? '' : ' '); + } else { + $att .= $key . ' '; + } + } + + return $att; + } +} diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php index 075112de..e4093075 100644 --- a/app/Helpers/rss_helper.php +++ b/app/Helpers/rss_helper.php @@ -364,22 +364,16 @@ if (! function_exists('get_rss_feed')) { foreach ($episode->persons as $person) { foreach ($person->roles as $role) { - $personElement = $item->addChild( - 'person', - htmlspecialchars($person->full_name), - $podcastNamespace, - ); + $personElement = $item->addChild('person', esc($person->full_name), $podcastNamespace,); $personElement->addAttribute( 'role', - htmlspecialchars( - lang("PersonsTaxonomy.persons.{$role->group}.roles.{$role->role}.label", [], 'en'), - ), + esc(lang("PersonsTaxonomy.persons.{$role->group}.roles.{$role->role}.label", [], 'en'),), ); $personElement->addAttribute( 'group', - htmlspecialchars(lang("PersonsTaxonomy.persons.{$role->group}.label", [], 'en')), + esc(lang("PersonsTaxonomy.persons.{$role->group}.label", [], 'en')), ); $personElement->addAttribute('img', $person->avatar->medium_url); diff --git a/app/Helpers/seo_helper.php b/app/Helpers/seo_helper.php index 284af093..473df8ad 100644 --- a/app/Helpers/seo_helper.php +++ b/app/Helpers/seo_helper.php @@ -30,8 +30,8 @@ if (! function_exists('get_podcast_metatags')) { $schema = new Schema( new Thing('PodcastSeries', [ - 'name' => esc($podcast->title), - 'headline' => esc($podcast->title), + 'name' => $podcast->title, + 'headline' => $podcast->title, 'url' => current_url(), 'sameAs' => $podcast->link, 'identifier' => $podcast->guid, @@ -39,8 +39,8 @@ if (! function_exists('get_podcast_metatags')) { 'description' => $podcast->description, 'webFeed' => $podcast->feed_url, 'accessMode' => 'auditory', - 'author' => esc($podcast->owner_name), - 'creator' => esc($podcast->owner_name), + 'author' => $podcast->owner_name, + 'creator' => $podcast->owner_name, 'publisher' => $podcast->publisher, 'inLanguage' => $podcast->language_code, 'genre' => $category, @@ -50,8 +50,8 @@ if (! function_exists('get_podcast_metatags')) { $metatags = new MetaTags(); $metatags - ->title(esc($podcast->title) . ' (@' . esc($podcast->handle) . ') • ' . lang('Podcast.' . $page)) - ->description(htmlspecialchars($podcast->description)) + ->title($podcast->title . ' (@' . $podcast->handle . ') • ' . lang('Podcast.' . $page)) + ->description(esc($podcast->description)) ->image((string) $podcast->cover->og_url) ->canonical((string) current_url()) ->og('image:width', (string) config('Images')->podcastCoverSizes['og']['width']) @@ -80,7 +80,7 @@ if (! function_exists('get_episode_metatags')) { $schema = new Schema( new Thing('PodcastEpisode', [ 'url' => url_to('episode', esc($episode->podcast->handle), $episode->slug), - 'name' => esc($episode->title), + 'name' => $episode->title, 'image' => $episode->cover->feed_url, 'description' => $episode->description, 'datePublished' => $episode->published_at->format(DATE_ISO8601), @@ -90,7 +90,7 @@ if (! function_exists('get_episode_metatags')) { 'contentUrl' => $episode->audio->file_url, ]), 'partOfSeries' => new Thing('PodcastSeries', [ - 'name' => esc($episode->podcast->title), + 'name' => $episode->podcast->title, 'url' => $episode->podcast->link, ]), ]) @@ -271,7 +271,7 @@ if (! function_exists('get_home_metatags')) { { $metatags = new MetaTags(); $metatags - ->title(esc(service('settings')->get('App.siteName'))) + ->title(service('settings')->get('App.siteName')) ->description(esc(service('settings')->get('App.siteDescription'))) ->image(service('settings')->get('App.siteIcon')['512']) ->canonical((string) current_url()) @@ -287,9 +287,9 @@ if (! function_exists('get_page_metatags')) { $metatags = new MetaTags(); $metatags ->title( - esc($page->title) . service('settings')->get('App.siteTitleSeparator') . esc(service( + $page->title . service('settings')->get('App.siteTitleSeparator') . service( 'settings' - )->get('App.siteName')) + )->get('App.siteName') ) ->description(esc(service('settings')->get('App.siteDescription'))) ->image(service('settings')->get('App.siteIcon')['512']) diff --git a/app/Resources/js/modules/markdown-preview.ts b/app/Resources/js/modules/markdown-preview.ts index ed0c5a91..58733f7b 100644 --- a/app/Resources/js/modules/markdown-preview.ts +++ b/app/Resources/js/modules/markdown-preview.ts @@ -47,11 +47,20 @@ export class MarkdownPreview extends LitElement { return link.replace(" { + return unsafe + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll('"', """) + .replaceAll("'", "'"); + }; + static styles = css` * { max-width: 65ch; diff --git a/app/Views/Components/Forms/FormComponent.php b/app/Views/Components/Forms/FormComponent.php index 941f0814..d8883e04 100644 --- a/app/Views/Components/Forms/FormComponent.php +++ b/app/Views/Components/Forms/FormComponent.php @@ -31,6 +31,11 @@ class FormComponent extends Component } } + public function setValue(string $value): void + { + $this->value = htmlspecialchars_decode($value, ENT_QUOTES); + } + public function setRequired(string $value): void { $this->required = $value === 'true'; diff --git a/app/Views/Components/Forms/MarkdownEditor.php b/app/Views/Components/Forms/MarkdownEditor.php index 66fb54c2..617c05a2 100644 --- a/app/Views/Components/Forms/MarkdownEditor.php +++ b/app/Views/Components/Forms/MarkdownEditor.php @@ -23,13 +23,7 @@ class MarkdownEditor extends FormComponent $this->attributes['class'] = 'bg-elevated border-none focus:border-none focus:outline-none focus:ring-0 w-full h-full'; $this->attributes['rows'] = 6; - $value = htmlspecialchars_decode($this->value); - - $oldValue = old($this->name); - if ($oldValue === null) { - $oldValue = $value; - } - $textarea = form_textarea($this->attributes, $oldValue); + $textarea = form_markdown_textarea($this->attributes, old($this->name, $this->value)); $markdownIcon = icon( 'markdown', 'mr-1 text-lg opacity-40' diff --git a/themes/cp_admin/episode/create.php b/themes/cp_admin/episode/create.php index a327ff86..61f05073 100644 --- a/themes/cp_admin/episode/create.php +++ b/themes/cp_admin/episode/create.php @@ -126,7 +126,7 @@ name="description_footer" label="" hint="" - value="episode_description_footer_markdown) ?? '' ?>" + value="episode_description_footer_markdown) ?? '' ?>" disallowList="header,quote" /> diff --git a/themes/cp_admin/episode/edit.php b/themes/cp_admin/episode/edit.php index 70453ca3..5611b60b 100644 --- a/themes/cp_admin/episode/edit.php +++ b/themes/cp_admin/episode/edit.php @@ -122,7 +122,7 @@ as="MarkdownEditor" name="description" label="" - value="description_markdown) ?>" + value="description_markdown) ?>" required="true" disallowList="header,quote" /> @@ -131,7 +131,7 @@ name="description_footer" label="" hint="" - value="episode_description_footer_markdown) ?? '' ?>" + value="episode_description_footer_markdown) ?? '' ?>" disallowList="header,quote" /> diff --git a/themes/cp_admin/episode/embed.php b/themes/cp_admin/episode/embed.php index 16057d97..f633a04a 100644 --- a/themes/cp_admin/episode/embed.php +++ b/themes/cp_admin/episode/embed.php @@ -32,7 +32,7 @@
- +
diff --git a/themes/cp_admin/episode/publish_edit.php b/themes/cp_admin/episode/publish_edit.php index 71448753..56af8dfd 100644 --- a/themes/cp_admin/episode/publish_edit.php +++ b/themes/cp_admin/episode/publish_edit.php @@ -39,7 +39,7 @@
- +
diff --git a/themes/cp_admin/podcast/edit.php b/themes/cp_admin/podcast/edit.php index 661c1111..527e3544 100644 --- a/themes/cp_admin/podcast/edit.php +++ b/themes/cp_admin/podcast/edit.php @@ -67,7 +67,7 @@ as="MarkdownEditor" name="description" label="" - value="description_markdown) ?>" + value="description_markdown) ?>" required="true" disallowList="header,quote" /> diff --git a/themes/cp_admin/settings/theme.php b/themes/cp_admin/settings/theme.php index 93d321f3..4757a214 100644 --- a/themes/cp_admin/settings/theme.php +++ b/themes/cp_admin/settings/theme.php @@ -20,7 +20,7 @@ themes as $themeName => $color): ?> diff --git a/themes/cp_app/embed.php b/themes/cp_app/embed.php index 8e858f0b..3dc10c61 100644 --- a/themes/cp_app/embed.php +++ b/themes/cp_app/embed.php @@ -6,7 +6,7 @@ <?= esc($episode->title) ?> -
- +