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

fixes interactive.harbor issues. ref #3418 #3420

Merged
merged 4 commits into from
Sep 24, 2023
Merged

Conversation

ghostnumber7
Copy link
Contributor

Sorry ... closed previous PR by mistake

Copy link
Member

@toots toots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your contribution! I added an implementation of the function using our standard API functions.

I'm approving to make sure there's no more friction. If you wouldn't mind applying the changes, we should be ready to go!

Comment on lines 385 to 400
# Escape HTML entities.
# @category String
def string.escape.html(s) =
r/[&<>"']/g.replace(
fun (c) -> begin
if c == "&" then "&amp;"
elsif c == "<" then "&lt;"
elsif c == ">" then "&gt;"
elsif c == '"' then "&quot;"
elsif c == "'" then "&#39;"
else c
end
end,
s
)
end
Copy link
Member

@toots toots Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a standardized escaping routine using string.escape. This can make the implementation easier to extend and I suspect faster.

Here's an implementation using it with the %argsof/@argsof pre-processing to re-use the argument declaration and documentation from the function:

Suggested change
# Escape HTML entities.
# @category String
def string.escape.html(s) =
r/[&<>"']/g.replace(
fun (c) -> begin
if c == "&" then "&amp;"
elsif c == "<" then "&lt;"
elsif c == ">" then "&gt;"
elsif c == '"' then "&quot;"
elsif c == "'" then "&#39;"
else c
end
end,
s
)
end
# Escape HTML entities.
# @category String
# @argsof string.escape[encoding]
def string.escape.html(%argsof(string.escape[encoding]), s) =
escaped =
[
("&", "&amp;"),
("<", "&lt;"),
(">", "&gt;"),
('"', "&quot;"),
("'", "&#39;")
]
def special_char(~encoding=_, c) =
list.assoc.mem(c, escaped)
end
def escape_char(~encoding=_, c) =
escaped[c]
end
string.escape(
%argsof(string.escape[encoding]),
special_char=special_char,
escape_char=escape_char,
s
)
end

@vitoyucepi
Copy link
Collaborator

I apologize, I did not realize that there was a new one.
#3419 (comment)

@ghostnumber7
Copy link
Contributor Author

I apologize, I did not realize that there was a new one. #3419 (comment)

Was my mistake :) ... i got the test thing going with ./liquidsoap tests/test.liq tests/language/string.liq (working nicely). Implemented your last suggestion

@@ -495,7 +495,7 @@ def interactive.harbor(
}
}
if (interactive[i].type != 'button') {
data = data.concat(interactive[i].name+'='+interactive[i].value)+'&';
data = data.concat(interactive[i].name+'='+encodeURIComponent(interactive[i].value))+'&';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just me, or encodeURIComponent doesn't exist?

Copy link
Contributor Author

@ghostnumber7 ghostnumber7 Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodeURIComponent is on javascript side. It's standard (doc). Basically there to fix the issues with =&+ chars. Needed because those are special chars for URLs only (=& used for querystrings and + used as an space). Alternative solution would be to change the method to POST instead of using GET and using multipart/form-data or alike

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just figured out this is a JS code.

@toots
Copy link
Member

toots commented Sep 24, 2023

@ghostnumber7 do you mind if I apply my proposed changes and gets this merged and backported to rolling-release-v2.2.x?

@ghostnumber7
Copy link
Contributor Author

@ghostnumber7 do you mind if I apply my proposed changes and gets this merged and backported to rolling-release-v2.2.x?

Already applied your suggestion. You can go ahead with the merging

@toots toots disabled auto-merge September 24, 2023 15:02
@toots toots merged commit 81f4bca into savonet:main Sep 24, 2023
23 of 25 checks passed
@toots
Copy link
Member

toots commented Sep 24, 2023

Merged. Thanks a lot for this!

toots pushed a commit that referenced this pull request Sep 24, 2023
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 this pull request may close these issues.

3 participants