-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove `Phlex::SGML#unsafe_raw` - Add `Phlex::SGML#safe` which creates a `Phlex::SGML::SafeValue` - Add `Phlex::SGML::SafeObject` a generic interface for safe objects, which `Phlex::SGML::SafeValue` implements - Add `Phlex::SGML#raw`, which takes a SafeObject - Update `__attributes__` to allow the use of unsafe attribute names when the values are SafeObjects. Example ```ruby def view_template raw 🦺 "<script>" a href: 🦺 "javascript:alert(1)" a onclick: 🦺 "alert(1)" end ``` Thanks @bradgessler for writing the original implementation of this PR. #719 Closes #718
- Loading branch information
1 parent
1f8ec39
commit d27e244
Showing
7 changed files
with
80 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.3.3 | ||
3.3.5 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ruby 3.3.3 | ||
ruby 3.3.5 |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
# @api private | ||
module Phlex::SGML::SafeObject | ||
# This is included in objects that are safe to render in an SGML context. | ||
# They must implement a `to_s` method that returns a string. | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Phlex::SGML::SafeValue | ||
include Phlex::SGML::SafeObject | ||
|
||
def initialize(to_s) | ||
@to_s = to_s | ||
end | ||
|
||
attr_reader :to_s | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class Example < Phlex::HTML | ||
def view_template | ||
a( | ||
onclick: safe("window.history.back()"), | ||
href: safe("javascript:window.history.back()"), | ||
) | ||
end | ||
end | ||
|
||
test "safe value" do | ||
expect(Example.call) == %(<a onclick="window.history.back()" href="javascript:window.history.back()"></a>) | ||
end |
This file contains 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