Create proper shim for xss library

Create proper shim for xss library

diff --git a/app/assets/javascripts/discourse-shims.js b/app/assets/javascripts/discourse-shims.js
index d6ccfbe..384fb92 100644
--- a/app/assets/javascripts/discourse-shims.js
+++ b/app/assets/javascripts/discourse-shims.js
@@ -25,6 +25,10 @@ define("bootbox", ["exports"], function (__exports__) {
   __exports__.default = window.bootbox;
 });
 
+define("xss", ["exports"], function (__exports__) {
+  __exports__.default = window.filterXSS;
+});
+
 define("mousetrap", ["exports"], function (__exports__) {
   __exports__.default = window.Mousetrap;
 });
diff --git a/app/assets/javascripts/pretty-text-bundle.js b/app/assets/javascripts/pretty-text-bundle.js
index 62dd6c1..2a3862f 100644
--- a/app/assets/javascripts/pretty-text-bundle.js
+++ b/app/assets/javascripts/pretty-text-bundle.js
@@ -6,7 +6,6 @@
 //= require ./pretty-text/addon/emoji
 //= require ./pretty-text/addon/engines/discourse-markdown-it
 //= require xss.min
-//= require ./pretty-text/addon/xss
 //= require ./pretty-text/addon/white-lister
 //= require ./pretty-text/addon/sanitizer
 //= require ./pretty-text/addon/oneboxer
diff --git a/app/assets/javascripts/pretty-text/addon/sanitizer.js b/app/assets/javascripts/pretty-text/addon/sanitizer.js
index 26eef20..aaf8005 100644
--- a/app/assets/javascripts/pretty-text/addon/sanitizer.js
+++ b/app/assets/javascripts/pretty-text/addon/sanitizer.js
@@ -1,4 +1,4 @@
-import xss from "pretty-text/xss";
+import xss from "xss";
 
 function attr(name, value) {
   if (value) {
diff --git a/app/assets/javascripts/pretty-text/addon/xss.js b/app/assets/javascripts/pretty-text/addon/xss.js
deleted file mode 100644
index d2189b1..0000000
--- a/app/assets/javascripts/pretty-text/addon/xss.js
+++ /dev/null
@@ -1,2 +0,0 @@
-// Shim for xss.js library
-export default window.filterXSS;

GitHub sha: 30e91125

I reverted this in Revert "Create proper shim for xss library" · discourse/discourse@e3b4632 · GitHub because it breaks the build.

     Failure/Error: ctx.load("#{Rails.root}/lib/pretty_text/shims.js")
     
     MiniRacer::RuntimeError:
       Error: Could not find module `xss` imported from `pretty-text/sanitizer`
     # JavaScript at requireFrom (<anonymous>:290:13)
     # JavaScript at reify (<anonymous>:259:22)
     # JavaScript at obj (<anonymous>:337:19)
     # JavaScript at tryFinally (<anonymous>:168:14)
     # JavaScript at require (<anonymous>:335:5)
     # JavaScript at requireFrom (<anonymous>:294:12)
     # JavaScript at reify (<anonymous>:259:22)
     # JavaScript at obj (<anonymous>:337:19)
     # JavaScript at tryFinally (<anonymous>:168:14)
     # JavaScript at require (<anonymous>:335:5)
     # ./lib/pretty_text.rb:94:in `create_es6_context'
     # ./lib/pretty_text.rb:125:in `block in v8'
     # ./lib/pretty_text.rb:123:in `synchronize'
     # ./lib/pretty_text.rb:123:in `v8'
     # ./lib/pretty_text.rb:251:in `block in escape_emoji'
     # ./lib/pretty_text.rb:455:in `block in protect'
     # ./lib/pretty_text.rb:454:in `synchronize'
     # ./lib/pretty_text.rb:454:in `protect'
     # ./lib/pretty_text.rb:250:in `escape_emoji'
     # ./app/models/emoji.rb:186:in `unicode_unescape'
     # ./lib/validators/max_emojis_validator.rb:6:in `validate_each'
     # ./spec/models/user_stat_spec.rb:93:in `block (3 levels) in <top (required)>'

It looks like the shim should have been added to discourse/shims.js at master · discourse/discourse · GitHub?

Sorry about that @tgxworld - for some reason I was not notified of breaking the build. I’ll sort it out!

@eviltrout The build was disabled because of the deploy which is why the tests did not run xD

1 Like

Aha! That explains it :slight_smile: