LP#1857710: fix Angular client whitescreen on Firefox
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 27 Dec 2019 18:21:15 +0000 (13:21 -0500)
committerJason Boyer <JBoyer@eoli.info>
Fri, 27 Dec 2019 20:41:37 +0000 (15:41 -0500)
Work done for LP#1830391 added an instance of a Javascript
regexp replace using the dotAll ("/s") flag, but as of the moment
Firefox treats that flag as a fatal syntax error, breaking the
Angular staff client.

To test
-------
[1] Attempt to log in the Angular staff client with Firefox. Note
    that you get a whitescreen with the following in the browser
    console:

    SyntaxError: invalid regular expression flag s
[2] Apply the patch and repeat step 1. This time, the Angular
    staff client should work normally.
[3] Verify that the Angular unit tests pass.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Jason Boyer <JBoyer@eoli.info>

Open-ILS/src/eg2/src/app/share/util/htmltotxt.service.spec.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/share/util/htmltotxt.service.ts

diff --git a/Open-ILS/src/eg2/src/app/share/util/htmltotxt.service.spec.ts b/Open-ILS/src/eg2/src/app/share/util/htmltotxt.service.spec.ts
new file mode 100644 (file)
index 0000000..1d2345c
--- /dev/null
@@ -0,0 +1,15 @@
+import {HtmlToTxtService} from './htmltotxt.service';
+
+let h2txt: HtmlToTxtService;
+
+beforeEach(() => {
+    h2txt = new HtmlToTxtService();
+});
+
+describe('HtmlToTxtService', () => {
+    it('htmlToTxt cleans multiline comments', () => {
+        // this is a regression test for LP#1857710 on Firefox
+        const str = '<h1>A print template</h1> <!-- I am a comment\nwith an embedded newline --> <div>body of template</div>';
+        expect(h2txt.htmlToTxt(str)).toEqual('A print template  body of template');
+    });
+});
index e265b3d..25b602c 100644 (file)
@@ -38,7 +38,11 @@ export class HtmlToTxtService {
         }
 
         // First remove multi-line comments.
-        html = html.replace(/<!--(.*?)-->/gs, '');
+        // NOTE: the regexp was originally /<!--(.*?)-->/gs
+        //       but as of 2019-12-27 Firefox does not support
+        //       the ES2018 regexp dotAll flag and Angular/tsc doesn't
+        //       seem set up to transpile it
+        html = html.replace(/<!--([^]*?)-->/g, '');
 
         const lines = html.split(/\n/);
         const newLines = [];