Repository navigation
fix(links): don't open links in a new window when the flag is unchecked - #267
Open
TheRealAnubis wants to merge 1 commit into
Open
TheRealAnubis wants to merge 1 commit into
TheRealAnubis wants to merge 1 commit into
Conversation
The link form of the editor submits the "Open in a new window" flag
through a hidden field, so it gets stored as a string ("false", or ""
when it was never set). `Maglev::Content::Link#open_new_window?` used
`!!`, which treats those strings as true and renders target="_blank"
on every link edited in the editor.
- cast the flag to a boolean when rendering the link (fixes the links
already stored with a string value)
- cast it when the link setting is saved, like the checkbox settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Links edited in the editor always render with
target="_blank", even when "Open in a new window" is unchecked.Root cause: the URL link form submits the flag through a hidden field (
Maglev::Uikit::Form::Link::UrlLinkComponent), so it's stored as a string:"false", or""when it was never set.Maglev::Content::Link#open_new_window?uses!!link[:open_new_window], which treats any string as true.Fix:
Maglev::Content::Link#open_new_window?casts the value withActiveModel::Type::Boolean, so links already stored with a string value render correctly.Maglev::SettingTypes::Link#cast_valuecastsopen_new_windowto a boolean when the setting is saved (only if the key is present), like the checkbox settings since d5e18e8.Tests:
spec/components/maglev/content/link_spec.rb:open_new_window?/target_blankwith"true","false"and"".spec/models/maglev/setting_types/link_spec.rb:cast_valuewith"true","1","false","0"and"".Found while running Maglev 3.1.0 in production, where we've been carrying a monkey-patch for it.