-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Deprecation of Handlebars.SafeString prevents clear checks if something is a SafeString #13318
Comments
Can you help me understand why you need to check if a given string is a SafeString? |
We were using this in a test, verifying that our helper returned a SafeString. |
I have some library code that uses this to emit a warning when an unsafe string was passed. |
@dustyjewett - Wouldn't it be better to just use the helper, and ensure its return value was displayed as HTML?
|
@topaxi - We generally use a |
@rwjblue We certainly test that our end result is as-expected, but because SafeString has an explicit impact in how helpers are rendered into the DOM, we want to check that as well. To get around this issue, we verify that the return object is NOT a string, but that the .toString() is as-expected. But that is just testing known ways that things might go wrong, we can't check the actual, expected behavior. (also, many of our objects have toHTML methods, so checking that won't ensure that we didn't accidentally just return one of our other classes) |
@dustyjewett sounds like the deprecation has a side-effect if you expect to check the instance, I'm curious how hard would it be in your app to make the suggested change to (I'm looking for a workaround, my best guess is that the deprecation may not change for this use case.) |
I think we may need to expose a utility function. Something like |
@pixelhandler: I believe we already changed to htmlSafe(), but it still doesn't give us a way to confirm that an object is a SafeString. I'm fine with duck-typing... adding isSafeString:true to the object(s) would be fine with me... just some way to check.
|
Ya, I was saying we might need to provide a method (not adding a prop to the objects). Adding a property to the object, doesn't prevent against issues where you may be |
If you used a "special" property where the value was a reference to a known function it shouldn't be |
If there is a use-case for detecting safe strings, I expect it would make a good feature addition. |
@mixonic - Yes, precisely. |
Copy over from #13354: In our app we have a few occasions where we do See: 0e95d7c The problem is that the function SafeString is no longer publically accessible. What was Ember.Handlebars.SafeString is now a wrapper function around htmlSafe. It isn't just our app either. While submitting a PR to Ember-i18n I discovered their tests are broken because they too do not have access to this function. See: https://github.com/jamesarosen/ember-i18n/blob/master/tests/unit/utils/i18n/default-compiler-test.js#L56-L59 Addtionally, if you search for While I really like @mixonic's suggestion for EDIT: I have some bandwidth at the moment, I'd be happy to submit a PR for |
I think the I am a bit torn here, as I really do think we should deprecate |
@workmanw - Would you mind working up the RFC? |
@rwjblue I was just responding with: "I'll get the ball rolling on the RFC PR and build a polyfill." :) |
Submitted #13442 to remove. |
@rwjblue Probably okay to close now that is Polyfill solution is available here: https://github.com/workmanw/ember-string-ishtmlsafe-polyfill |
Thanks! |
With the deprecation of Handlebars.SafeString, the constructor chain of SafeString doesn't include Handlebars.SafeString, making instanceof checks fail.
See Twiddle: https://ember-twiddle.com/32e5e3818cd66aa224f5a422fdafd83a?openFiles=controllers.application.js%2C
For context, the latest change in the chain, fixing the deprecation:
https://github.com/emberjs/ember.js/pull/13226/files
The text was updated successfully, but these errors were encountered: