i am trying to add a signature in a pdf in powerapps using the peninput field. i add the following in the html file which file is successfully converted in pdf through the flow
<img src='"& JSON(PenInput4.Image; JSONFormat.IgnoreBinaryData) &"'
style='width:80px;height:50px'></img>
but i see this in the pdf a box with an x on the top left corner.
thank you!
The result of the JSON function already includes quotes, so you are "double-quoting" the image source. This is what you have:
<img src='"data:image/png;base64,..."' style='...'></img>
You can either use the double quotes (") that are returned by the JSON function:
"<img src=" & JSON(PenInput4.Image; JSONFormat.IncludeBinaryData) &
" style='width:80px;height:50px'></img>"
Or you if you want to use single quotes (') in your HTML document, you can keep your single quotes and remove the double quotes from the JSON output:
Set(penInputEncodedImage, JSON(PenInput4.Image; JSONFormat.IncludeBinaryData));;
...
"<img src='" &
Mid(penInputEncodedImage, 2, Len(penInputEncodedImage) - 2) &
"' style='width:80px;height:50px'></img>"
Just a final note: you are using JSONFormat.IgnoreBinaryData - the correct flag to be able to encode images should be JSONFormat.IncludeBinaryData. It seems to be working today, but that goes against the documentation so it is a bug that may be fixed someday.
Related
I'm having trouble displaying links to URLs with quotes in them and can't figure out a solution despite a load of examples on stackoverflow! Here's the exact string I'm storing in my database (shows Adelaide Antartica)
https://www.google.com/maps/place/67%C2%B007'27.3%22S+68%C2%B008'56.0%22W/#-67.1447827,-68.3886741,71373m/data=!3m1!1e3!4m5!3m4!1s0x0:0x0!8m2!3d-67.124258!4d-68.148903
When I just try putting that into a href it links to...
https://www.google.com/maps/place/67%C2%B007 (i.e. breaks at the first single quote)
But I try using href="encodeURI(theLink)" or href="encodeURIComponent(theLink)" it links to the same thing (I even tried the decode options in case I was thinking about it the wrong way and had the same problem).
Does anyone have a recommendation on the best way to proceed here? I even tried the deprecated "escape" function which also won't work for me. Thanks for any thoughts at all!
(p.s. funnily enough as I'm writing this I see that even Stack Overflow's link is broken in exactly the same way - maybe it's not even possible?!)
EDIT: As requested by Clemzd - I'm using d3 to construct the links, so doing this...
anElement.append("text").html("<a href='" + myData[i].url + "'> a link name </a>");
Works great on everything but links with a single quote regardless of whether I do encodeURI(myData[i].url) or not
You use single quotes to delimit the value of the href attribute, so that value cannot contain unescaped single quotes. That's an issue with HTML markup encoding, not URL encoding.
You can either reverse your use of single and double quotes (encoded URLs cannot contain double quotes, but they can contain single quotes) or replace the single quotes in the URL with a character entity like '. URL encoding by %27 would also work, but that's not a standard encoding that encodeURIComponent does.
There are many ways to solve your issue. All you need to know is if your input may contains ' then you have to escape this character. Otherwise you will get something like anElement.append("text").html("<a href='" + https://www.google.com/maps/place/'link + "'> a link name </a>"); That can't be parsed because of the '.
If you are sure that your link will never contains " then change your code and use " instead as a concatenaion operator.
If not, you can escape ' in server side or client side. For example in client side you can do :
function escapeJavascript(input){
return input.replace(/\\n/g, "\\n")
.replace(/\\'/g, "\\'")
.replace(/\\"/g, '\\"')
.replace(/\\&/g, "\\&")
.replace(/\\r/g, "\\r")
.replace(/\\t/g, "\\t")
.replace(/\\b/g, "\\b")
.replace(/\\f/g, "\\f");
}
And then use it like this: anElement.append("text").html("<a href='" + escapeJavascript(myData[i].url) + "'> a link name </a>");
I'm trying to update a html file. which has following tags
The tune2fs allows you to convert an ext2 file system to
The content is available on online-html editor,when copy-paste(ctrl/c + ctrl+v) the content and add it file, it becomes
he+%3Cb%3Etune2fs%3C%2Fb%3E+allows+you+to+convert+an+%3Cb%3Eext2%3C%2Fb%3E+file+system
does copy/paste adds some chars? Why this happens and is it possible to prevent this?
this is not programming question, but something like copy/paste buffer or creates this issue?
That is HTML that has been URL encoded into <b> and </b> tags. You can change "%3Cb%3E" to "<b>" and "%3C%2Fb%3E" to "</b>". Also note that + is the URL encoded form of " " (space). Alternatively, you could plug it into any URLDecoder and it will decode it for you.
I am writing html files from a stack. This is a bit of a pain because for every line I have to write something like the following if the file contains quotes.
write "<div id=hidden-" & quote & myKanton & quote && "style=" & quote & "display:block;" "e&&"class=" "e & "popuptable" "e& ">" & LF to file tOutputFileCH
Now I have to add a lot of html code again and I'm wondering if there is an easier way to be able to do something like:
write escaped("my html numbers and "txt" with quotes") to file
I do not need variables within the html text.
Often, people use functions like
function q theText
replace "'" with quote in theText
return theText
end q
which can be used as
write q("<div id=hidden-'" & myKanton & "' style='display:block;'" & "class='popuptable'>" & LF) to file tOutputFileCH
You can use a string like in above example but you can also use any container:
get q(myVariable)
put q(it) into field 1
put q(field 1) into field 2
put q(url myUrl) into url myOtherUrl
put q(the cProperty of me) into myVar
-- etc etc etc
You can also use ยด or ` instead of ' if you change the q function.
By the way, I noticed that you don't include hidden- in the quotes. Are you sure that's correct?
HTML allows use of quotes and single quotes, so you can...
put "<div style='border:1px'>" into tHTML
LiveCode's format command allows you to escape double quotes...
put format("my html numbers and \"txt\" with quotes") into tData
It is working now. I put the html lines in a custom stack property and use that as input when writing the file. Works perfectly. It even seems to work without the q function.
write ( the cMapOverlay of stack "AfaConverter" ) & LF to file tOutputFileCH
I also tried that because
onmouseover="nhpup.popup($('#hidden-VS').html(), {'width': 400});" href="./kantone/index_kanton_VS.html"
this is trouble with q without adaptions because ' is replaced with " which is a problem.
There are some good answers here. Let me suggest another approach. You could use a quoting function, but in a slightly different way:
function q pString
return quote & pString & quote
end q
Then use the LiveCode merge() function. Merge evaluates any LiveCode expression or variable enclosed in [[ ]] and incorporates it into the enclosing quoted text:
write merge("my html numbers and [[q("txt")]]") to file
When processing a html form, I need to append some text to a text field before saving it to database. To make it prettier, I need to add a line feed in between:
userText = userText + "<br>" + appendedText;
# save userText in database
The problem is,when fetching the text to render web page, for protection agains XSS, I need to escape text from database before rendering. Thus, <br> in userText is rendered as <br> instead of a line feed.
So I am wondering if there is any other way to produce a line feed other than <br>?
I have tried "\n" "\r\n", and "
", none of them work.
Also, the appended text is in the same element with original text, so css with 'display:block' is out of the question.
use \n and then after fetching the data from the database and prior to outputting it, replace all the \n with <br />.
This way you are still safe for XSS, and you have full control over the output.
If you are using javaScript to get the form values you can easily use "\n" to add a new line to the value you want to save;
var toSave = FormValue + "\n\n" + "extratext";
Demo here
Take this for example: <a href="manageCart.php?action=remove&id=49">
When validated, you will get this result:
Line 26, Column 802: & did not start a character reference. (& probably should have been escaped as &.)
But this is not content, so the & is necessary. What is done to make it valid html?
<a href="manageCart.php?action=remove&id=49">
Use &
validaters usually want & instead of just the & sign. when you click on the link it will still change it to & in the browsers url