Aurelia template parse error when string contains HTML entity for quote character - aurelia

When I try to feed a string to Aurelia from a template and the string contains HTML entities representing the same quoting character as those surrounding the string, I get parser errors. Apparently the HTML enitities are interpreted before they reach Aurelia, but I'm not sure shy.
For example:
${"Why wouldn't "this" work?"}
Results in
Error: Parser Error: Unconsumed token this at column 15 in expression ["Why wouldn't "this" work?"]
Could somebody tell me why entities are interpreted rather than just outputted to the DOM? And what can I do to get this to work?

it seems aurelia parser interprets &quot like equivalent to ".
This makes your expression look incorrect to the parser.
You should escape the " quotes like this:
${"Why wouldn't \"this\" work?"}
Regards.

Related

How to identify an element by classname containing curly brackets

when i try to access element:
browser.element('.object{ media }');
I get the following error message:
Error: Argument was an invalid selector (e.g. XPath/CSS).
at element(".object{ media }") - index.js:312:3
Is it possible to access elements by class name including curly brackets?
As per your question and your code trials to access desired element with classname containing curly brackets i.e. {} you can use the following solution:
XPath:
"//*[#class=\"object{ media }\"]"
Following what #DebanjanB said,
You can use something called Regular Expressions to sort issues like this out, what Debanjan has shown you is known as this.
Regular Expressions Guide
It would be useful if you read through a guide so you fully understand the code you are putting into your project, this will allow you to make better use of it later on in your testing.
All the best,
Jack

Django template excape literal string

Basically, is something like
{{ ">>"|escape }}
possible?
I can use {{ context_variable|escape}} but can I use a string literal?
I want to avoid littering my template files with >
Yes. Django treats invalid variables as an empty string. That's the case when you pass a string literal. I will have the string literal concatenated to an empty string.
There is also this answer here.
Literal HTML in Django without using a variable?

How does MessageBoxIcon Enumeration manage to have Error as part of it

I would like to create an Enumeration, one item of which would be Error. As Error is a keyword the compiler, as expected, points out that that is not on. As I have Option Strict On on by default I thought that possibly this would be one instance where setting it specifically to off would help. However it doesn't.
So put very simply how does the MessageBoxIcon manage to use Error as an item in its enumeration?
Enclose the Error keyword in square brackets
Public Enum SimpleSettings
[Error] = 0
Warn = 1
Correct = 2
End Enum
From the VB.NET Language specifications
Regular identifiers may not match keywords, but escaped identifiers
can. An escaped identifier is an identifier delimited by square
brackets. Escaped identifiers follow the same rules as regular
identifiers except that they may match keywords and may not have type
characters.
Try something like this:
Public Enum Foo
Bar
Faa
[Error]
End Enum

Serialize C# object using JSON.NET for Dojo data-dojo-props

Dojo's dijit html5 tags use an attribte name data-dojo-props. The value is basically a JSON string without quotes around the property names and without the outermost braces.
It looks something like this.
data-dojo-props="prop1:'xyz', prop2:true, prop3: { subprop1: 1, subprop2: 'abc'}"
I'm using C# to write this out from a C# object using JSON.NET and passing in the object pointer. I found settings to leave out the property name quotes, but I can't figure out a graceful way to remove the outside braces.
For now, I'll run the string through a regex to remove them, but was wondering if someone new a better way.
I serialize each top level property separately and make it a global javascript variable. I then reference that variable in data-dojo-props. I admit it's not that elegant.
My concern with your approach above, is if the value of subprop2 contains a quote, you will get a parser error.
<script type="text/javascript">
menuData = {THE SERIALIZED JSON GOES HERE};
</script>
<div data-dojo-type="SomeWidget" data-dojo-props="menuData: menuData"></div>

Escape dot from GString

I would like to learn how to escape dot in GString so groovy (1.8) does not treat it as a part of an variable inside sql.execute. I have the following code:
Map<String, String> dbSettings = [schemaName:"testSchema"];
String myDbPrefix = dbSetting.schemaName + ".";
sql.execute "DELETE FROM ${myDbPrefix}myTable"
And I got this error:
Ignoring groovy.lang.MissingPropertyException: No such property: myTable for class: java.lang.String
Clearly indicating that . was interpreted as part of variable ${myDbPrefix}.
Does escaping the embedded variable help?
  sql.execute "DELETE FROM ${Sql.expand myDbPrefix}myTable"
I got hit by this problem today. GStrings get handled by a special way in GroovySQL. It's mentioned in the javadoc. It does automatic parameter binding.
Each value in the GString will become a parameter (?) which gets set as a JDBC prepared statement parameter.
What a surprise!
I'm going to fix the problem in my application by subclassing the Sql class and overriding the GString handling with plain ".toString()" .
Documented in Groovy wiki:
GString Use Cases - GSQL Another use case for GString is GSQL where
parameters can be passed into SQL statements using this same mechanism
which makes for a neat way to integrate Groovy with other languages
like SQL. GroovySql then converts the expressions to ? and uses a JDBC
PreparedStatement and passes the values in, preserving their types.
If you explicitly want to coerce the GString to a String you can use
the toString() method. Groovy can also automatically coerce GStrings
into Strings for you.