Are single/double quotes allowed inside HTML attribute values?

Yes, both quotes are allowed in attribute values, but you must HTML-escape the quote you’re using as an attribute value delimiter, as well as other HTML-special characters like < and &: function encodeHTML(s) { return s.split(‘&’).join(‘&amp;’).split(‘<‘).join(‘&lt;’).split(‘”‘).join(‘&quot;’).split(“‘”).join(‘&#39;’); } var html=”<label my_attr=””+encodeHTML(attr_value)+'”>Text</label>’; However, you are usually much better off not trying to hack a document together from … Read more

PyYAML dump format

Below, ruamel.yaml is used instead. ruamel.yaml is actively maintained. Unlike PyYAML, ruamel.yaml supports: YAML <= 1.2. PyYAML only supports YAML <= 1.1. This is vital, as YAML 1.2 intentionally breaks backward compatibility with YAML 1.1 in several edge cases. This would usually be a bad thing. In this case, this renders YAML 1.2 a strict … Read more

How to handle double quotes in string before XPath evaluation?

PHP has Xpath 1.0, if you have a string with double and single quotes, a workaround is using the Xpath concat() function. A helper function can decide when to use what. Example/Usage: xpath_string(‘I lowe “double” quotes.’); // xpath: ‘I lowe “double” quotes.’ xpath_string(‘It\’s my life.’); // xpath: “It’s my life.” xpath_string(‘Say: “Hello\’sen”.’); // xpath: concat(‘Say: … Read more

Nesting quotes in JavaScript/HTML

You need to use proper escaping/encoding. Either in HTML using character references: <p onclick=”exampleFunc(‘&lt;div id=&quot;divId&quot;&gt;&lt;/div&gt;’);”>Some Text</p> Or in JavaScript using string escape sequences: <p onclick=”exampleFunc(‘\x3Cdiv\x20id\x3D\x22divId\x22\x3E\x3C/div\x3E’);”>Some Text</p>

How to escape history expansion exclamation mark ! inside a double quoted string?

In your last example, echo “$(echo ‘!b’)” the exclamation point is not single-quoted. Because history expansion occurs so early in the parsing process, the single quotes are just part of the double-quoted string; the parser hasn’t recognized the command substitution yet to establish a new context where the single quotes would be quoting operators. To … Read more