Conversation
rwjblue
left a comment
There was a problem hiding this comment.
I am very much in favor of this!!!
I think it may be useful to mention:
- that this can be easily polyfilled going back quite a ways
- that
{{html-safeis massively better and less trolly than{{{ - that
{{{is commonly linted against
Thanks for putting this together!!
text/0319-html-safe-helper.md
Outdated
|
|
||
| ## Motivation | ||
|
|
||
| Ember should encourage people to use `SafeString` and one way to do that is to make them easier to use. Soemtimes it can be inconvenient to use the `htmlSafe` function because it would require you to create a component when you otherwise wouldn't need one. This is especially common inside of {{#each}} blocks. If we had a `html-safe` helper than you could express this in the template. |
|
@rwjblue Great point. I hadn't considered it as a complete alternative to |
|
I think this should mention the trade-off of new API vs the existing triple curly way of doing it. Also, any confusion of which one is better to use, and if the existing {{{}}} should be a deprecation candidate. |
|
@kellyselden 👍 One of the benefits is that Question: does |
|
I didn't think about message passing benefits. That's a good one.
Just tested. Yes it does. |
|
I think this is a good idea. Pretty much all of our apps have this exact helper. |
|
I’m wondering about the name. It seems like a security troll because it’s easy for someone to assume that this makes a thing safe, when the opposite is true. (I know we already use this name in JS, and even there it’s not wonderful. But making it even more convenient to find and use means more beginner level devs will see it and use it.) Some of the comments here are making me wonder if even RFC readers are thinking of the full security implications of what htmlSafe does. Switching from triple curlies to this helper does not change your security — it just makes it harder to notice if you’re doing something dangerous. I’m especially concerned that people think this is a good way to avoid triple curly linter warnings, because it’s just a way to elude those very legitimate security warnings. Any project that lints for triple curlies should also lint for this new helper. I’m still in favor because I agree it’s better to be able to separate the location where you know a value is safe from the value where it’s ultimately bound into the DOM. But I want us to consider names that convey the gravity of what you’re doing. Just to throw one out: |
|
|
|
One more naming consideration: we should probably keep |
|
|
Perhaps |
I'm not sure that this is a completely apt name as, in Ember's case, the function isn't rendering anything. I do like how explicit the name is otherwise. Perhaps If we do use a name other than import { trustedHtml } from '@ember/string';
let html = trustedHtml('<div>someString</div>');or import { dangerousHtml } from '@ember/string';
let html = dangerousHtml('<div>someString</div>'); |
|
My points are:
Other than that, I like this RFC a lot. |
Yeah, I think that's an argument for adding the new name (I think |
If the RFC includes renaming the JS api to align it with the helper that's better. Although I'm unsure it is worth the churn TBH. |
|
We discussed this at the core team meeting on 2018-03-30 and decided we are not comfortable with this proposal and encourage the author to rework the existing APIs and new template helper to be clearer in their intent. |
|
We've had the exact concerns that @ef4 mentioned above about the name implying that it somehow makes the html "safe", and I've had to explain that to coworkers (after I understood it myself.) I personally like |
|
Rust went the opposite approach for doing something similar, the |
@mmun The author is you, right? :) What was the main objection? Would coming up with a good name make the intent clearer? (FWIW, I really like the |
|
@balinterdi yes and yes. I think even the Rust people don't think |
I think that, in retrospect, this has caused more confusion than something like I believe that |
|
Also, the thing I don't like about "dangerous" or "unsafe" is that it doesn't really tell you why what you're doing is unsafe, and people are willing to stab at it to make errors go away. On the other hand, "trust" is talking about the string ("you can trust the string"). I still think people will likely stab at it, but when they're doing so, they will more likely understand what they're saying. |
|
I also think that Rust's Instead of this current API: // some bytes, in a vector
let sparkle_heart = vec![240, 159, 146, 150];
let sparkle_heart = unsafe {
String::from_utf8_unchecked(sparkle_heart)
};
assert_eq!("💖", sparkle_heart);I think this API would be nicer: // some bytes, in a vector
let sparkle_heart = unsafe { AssertUTF8(vec![240, 159, 146, 150]) };
let sparkle_heart = String::from(sparkle_heart);
assert_eq!("💖", sparkle_heart);We have a similar situation with context: I want it to be possible to assert that some string has been validly escaped for HTML, CSS, script or whatever, rather than just marking a string as generally trusted. |
|
@mmun what's the current status of this RFC? Let me know if you don't have time to rework it, I'd be happy to draft a new RFC based on the discussion here |
|
@GavinJoyce if you are still interested, I would suggest you take the wheel! |
|
@locks 👍 I'll pick this up and work on a new RFC, thanks |
|
Here's a new RFC which proposes that we:
|
Rendered