Struts2 property tag. Force to escape single quote - tags

I have rather silly problem.
Struts2 property tag doesn't escape single quote ('). Such behavior breaks my JavaScript code.
It does do escape double quote (") using html entities, but not single quote (').
Is there any possibility to force property tag to replace single quote with appropriate html entity?
Example, string replaced with html entities.
Отредактированное событие с кавычкой "
The same with single qoute:
Отредактированное событие с кавычкой '
Is there any possibility to overcome such difficulty using standard approach? I wouldn't like to write some custom code.

You're in luck! By default, the tag only escapes HTML, but you can have it escape JavaScript too:
<s:property value="yourValue" escapeJavaScript="true"/>

Related

How to escape single quote in EJS template

my variable contains a string with an apostrophe or a single quote '
i'd like to display it with EJS.
I use
<img class="card-img-top" src='<%= data[i][0].omdb.Poster %>' alt='<%= data[i][0].omdb.Title; %>'>
When data[i][0].omdb.Title; contains an apostrophe, HTML is broken.
<%= is known to escape html. But not single quote!
How to do it? Any idea please?
I can't find anything on ejs doc.
<%= is known to escape html. But not single quote! How to do it?
Use double quotes around your attributes. Then single quotes won't matter.
(If you really want to use ' then you can do ...Poster.replace(/'/g, "&apos;")).

How do I format a string for use in an inline script rendered as HTML?

I have the following properties string
GET 50% OFF ANY M'EDIUM OR L"AR"GE PIZZA!
I am using it in an HTML onclick markup like so
onclick="trackPromoCta(encodeURI(${properties.ctaTwoTextRight # context='text'}));"
However this outputs invalid html. I tried #context of scriptString and that escapes but only for inside JavaScript not for inside HTML markup. I tried all of the other options as well and none of them actually escape special characters for rendering HTML.
I saw someone once use a #format to search the string for these characters and escape them for HTML but I can't find out how to use #format to do this.
The expected output should be
onclick="trackPromoCta(encodeURI('GET 50% OFF ANY M'EDIUM OR L"AR"GE PIZZA!'));"
Take a look at the HTL spec for display context: https://github.com/Adobe-Marketing-Cloud/htl-spec/blob/master/SPECIFICATION.md#121-display-context
What you need is scriptString since your string property will eventually be used as a javascript string literal.
${properties.jcr:title # context='scriptString'} <!--/* Applies JavaScript string escaping */-->
Also, you need to enclose your HTL expression with single quotes, for example:
var str = '${'this is a js string literla' # context='scriptString'}'
The HTL code for you specific example would be:
onclick="trackPromoCta(encodeURI('${properties.ctaTwoTextRight # context='scriptString'}'));"
The #context value "text", "html" or "attribute" will return encoded values in your resulting html. As per documentation too, text encodes all HTML special characters.
If you go through your html's code using "View Page Source" and not via "Inspect element of developer tools". You will see the expected outcome.
onclick="trackPromoCta(encodeURI('GET 50% OFF ANY M'EDIUM OR L"AR"GE PIZZA!'));"
Reference:
https://helpx.adobe.com/experience-manager/htl/using/expression-language.html

HTML entities in attributes with tinymce

When I have doble marks encoded in my HTML attributes, tinymce breaks that attributes.
For example:
data-value="ab&quote;----&quote;"> will be seen in source code: <div data-type="more-posts" data-value="ab">Hello</div>
http://codepen.io/anon/pen/MKYrbJ
How can I fix this?
If you would have real double quotes here your HTML would not be valid anymore because attributes use them.
It will be best do handle those when you save that content to your database.
You could replace them with single quotes - those wouldn't break the markup.

CKEditor: Is there a method to do escape character job?

The content output by the editor is with html tag,
but I want store them into the Mongodb, so I think I need to do a escape character job,
Is the ckeditor own escape character method?
BTW, is it necessary to do escape character job? Or I better convert them to other data format?
Native JS methods will solve your problem:
escape( 'Foo' )
> %3Ca%20href%3D%22%23%22%3EFoo%3C/a%3E
unescape( '%3Ca%20href%3D%22%23%22%3EFoo%3C/a%3E' )
> Foo

How to make Netbeans use single quotes in HTML tag attribute autocomplete?

When I type attribute in tag Netbeans automatically add two quotes:
<form method="|">
I want to make it use single quotes:
<form method='|'>
From my answer to a very similar question:
Type something like <div class= now your cursor should be in between two quote or double quote characters. You can now type the other type of quote character and it will change your preference.
I'm afraid, but it's pretty sure that double quotes are hard-coded into NetBeans.