Skip to content

Instantly share code, notes, and snippets.

@jdonaldson
Last active December 13, 2015 20:58
Show Gist options
  • Save jdonaldson/4973895 to your computer and use it in GitHub Desktop.
Save jdonaldson/4973895 to your computer and use it in GitHub Desktop.
class Test {
static function main() {
var f:Escaped = '<div>foo</div>';
var k:Foo = {k:'<div>blah!</div>'};
trace(f); // not escaped, simple trace
trace(k); // not escaped, simple trace
trace(f + ' some other string'); // escaped!
trace(k.k + ' extra'); // escaped as field access!
trace(k + " extra"); // escaped as autocasted concatenation!
trace(f.raw() + ' extra'); // unescaped concatenation
}
static function test(x:String){
trace(x);
}
}
abstract Escaped(String) {
public inline function new(s:String){
this = s;
}
public inline function raw(){
return this;
}
@:from static inline function fromString(s){
return new Escaped(s);
}
@:to static function toString(s){
return StringTools.htmlEscape(s) ;
}
}
typedef Foo = {
k:Escaped
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment