Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new kind of string literal for templates #9831

Closed
DartBot opened this issue Apr 10, 2013 · 3 comments
Closed

add new kind of string literal for templates #9831

DartBot opened this issue Apr 10, 2013 · 3 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Apr 10, 2013

This issue was originally filed by @tatumizer


Proposed new type of string literal - ideally, in backquotes (e.g. foo).
 
These strings are supposed to be used only in instance methods in a class, and be automatically compiled into invocation of method "handleTemplate" (exact name TBD):
void handleTemplate(String str, String templateStr), e.g.
class Foo {
   var sb=new StringBuffer();
   void handleTemplate(String str, String templateStr) {
      sb.write(str);
   }
   void example() {
      <h1>Customers</h1>; // calls handleTemplate
      for (customer in customers)
        <p>${customer.name}</p>; // calls handleTemplate
      // etc...
   }
}

As a second argument, system should pass original string as is (e.g. r'<p>${customer.name}</p>'), for the purposes of preventing injection of something bad. Example:
void handleTemplate(str, templateStr) {
  sb.write(ensureNoHtmlMarkup(str, templateStr));
}

These new literals will greatly simplify generation of all kinds of data: html, css, program code (generators) etc.

@sethladd
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Apr 11, 2013

This comment was originally written by @tatumizer


Probably, a better idea would be: instead of second parameter (templateStr), either provide a second method to sterilize each substituted token, or just drop this validation altogether. This feature is not supposed to achieve MORE than normal interpolation - it's just a sugar to automatically call method handleTemplate after interpolation is done. Sterilization of data is a different problem whatsoever, and can be solved by other means - e.g. with extra function call:
foo${sterilize(customer.name)}bar;

@gbracha
Copy link
Contributor

gbracha commented Aug 25, 2014

Set owner to @gbracha.
Added WontFix label.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 25, 2014
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants