David Notik
David Notik

Reputation: 2086

Sanitize HTML with HtmlEscape, only < and >

I'm having trouble with escaping HTML using HtmlEscape in dart:convert.

import 'dart:convert';

var sanitizer = new HtmlEscape(HtmlEscapeMode.ELEMENT);
var text = 'http://woven.co/';

print(text);
text = sanitizer.convert(text);
print(text); // http://woven.co/

Try it at: https://dartpad.dartlang.org/6036b7f888128b310a78

I expected the string not to change, given the HtmlEscapeMode.ELEMENT definition: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:convert.HtmlEscapeMode#id_ELEMENT

As well, for the life of me I can't figure out how to pass my own HtmlEscapeMode in.

Upvotes: 1

Views: 886

Answers (1)

Robert
Robert

Reputation: 5662

When I run the following code in the latest dev version (1.10.0-dev.1.10) I get the desired result. I guess dartpad uses and old version of dart.

import 'dart:convert';

main() {
  var sanitizer = new HtmlEscape(HtmlEscapeMode.ELEMENT);
  var text = 'http://woven.co/';

  print(text);
  text = sanitizer.convert(text);
  print(text);
}

http://woven.co/
http://woven.co/

Upvotes: 2

Related Questions