luci-base: luci.js: properly skip comments when finding require tokens
authorJo-Philipp Wich <jo@mein.io>
Fri, 29 May 2020 07:56:06 +0000 (09:56 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 29 May 2020 08:42:24 +0000 (10:42 +0200)
Fixes: #4020, #4022, #4111
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 6be8f8dbaee90a8a7e8bc87350f21793b9aed35c)

modules/luci-base/htdocs/luci-static/resources/luci.js

index 6579832104a73f6db4ecb0298d811e4f9ca99bc9..2ec96dd67262698c6c894e413edcac75f62a323e 100644 (file)
                                    args = '';
 
                                /* find require statements in source */
-                               for (var i = 0, off = -1, quote = -1, esc = false; i < source.length; i++) {
+                               for (var i = 0, off = -1, prev = -1, quote = -1, comment = -1, esc = false; i < source.length; i++) {
                                        var chr = source.charCodeAt(i);
 
                                        if (esc) {
                                                esc = false;
                                        }
+                                       else if (comment != -1) {
+                                               if ((comment == 47 && chr == 10) || (comment == 42 && prev == 42 && chr == 47))
+                                                       comment = -1;
+                                       }
+                                       else if ((chr == 42 || chr == 47) && prev == 47) {
+                                               comment = chr;
+                                       }
                                        else if (chr == 92) {
                                                esc = true;
                                        }
                                                off = i + 1;
                                                quote = chr;
                                        }
+
+                                       prev = chr;
                                }
 
                                /* load dependencies and instantiate class */