Last active
December 13, 2015 20:58
-
-
Save jdonaldson/4973895 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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