From c794a0e0f32d4606760cbb02b509394563d278cc Mon Sep 17 00:00:00 2001
From: nod_ <nod_@598310.no-reply.drupal.org>
Date: Mon, 29 Jan 2024 11:43:58 +0100
Subject: [PATCH] Issue #3416898 by Tom Konda, Tirupati_Singh: Use
 String.prototype.includes() instead of String.prototype.indexOf() where
 necessary

---
 core/misc/ajax.js                                | 2 +-
 core/misc/autocomplete.js                        | 5 +----
 core/misc/progress.js                            | 2 +-
 core/modules/contextual/js/contextual.js         | 2 +-
 core/modules/editor/js/editor.admin.js           | 2 +-
 core/modules/layout_builder/js/layout-builder.js | 3 +--
 core/modules/views/js/ajax_view.js               | 2 +-
 core/modules/views/js/base.js                    | 7 +++----
 core/modules/views_ui/js/views-admin.js          | 2 +-
 core/modules/views_ui/js/views_ui.listing.js     | 2 +-
 10 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/core/misc/ajax.js b/core/misc/ajax.js
index 4307d92e1cfc..ae1df4b9ed40 100644
--- a/core/misc/ajax.js
+++ b/core/misc/ajax.js
@@ -619,7 +619,7 @@
 
     // Ensure that we have a valid URL by adding ? when no query parameter is
     // yet available, otherwise append using &.
-    if (ajax.options.url.indexOf('?') === -1) {
+    if (!ajax.options.url.includes('?')) {
       ajax.options.url += '?';
     } else {
       ajax.options.url += '&';
diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js
index 74ca14e33eff..2d40f23bfd6a 100644
--- a/core/misc/autocomplete.js
+++ b/core/misc/autocomplete.js
@@ -79,10 +79,7 @@
 
     const term = autocomplete.extractLastTerm(event.target.value);
     // Abort search if the first character is in firstCharacterBlacklist.
-    if (
-      term.length > 0 &&
-      options.firstCharacterBlacklist.indexOf(term[0]) !== -1
-    ) {
+    if (term.length > 0 && options.firstCharacterBlacklist.includes(term[0])) {
       return false;
     }
     // Only search when the term is at least the minimum length.
diff --git a/core/misc/progress.js b/core/misc/progress.js
index ae1d2d7d1af8..bbf70365e1c3 100644
--- a/core/misc/progress.js
+++ b/core/misc/progress.js
@@ -125,7 +125,7 @@
           // When doing a post request, you need non-null data. Otherwise a
           // HTTP 411 or HTTP 406 (with Apache mod_security) error may result.
           let uri = this.uri;
-          if (uri.indexOf('?') === -1) {
+          if (!uri.includes('?')) {
             uri += '?';
           } else {
             uri += '&';
diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js
index 75abe445b567..52fb138e9ce3 100644
--- a/core/modules/contextual/js/contextual.js
+++ b/core/modules/contextual/js/contextual.js
@@ -104,7 +104,7 @@
     )}`;
     $contextual.find('.contextual-links a').each(function () {
       const url = this.getAttribute('href');
-      const glue = url.indexOf('?') === -1 ? '?' : '&';
+      const glue = url.includes('?') ? '&' : '?';
       this.setAttribute('href', url + glue + destination);
     });
 
diff --git a/core/modules/editor/js/editor.admin.js b/core/modules/editor/js/editor.admin.js
index ae4af589de68..6f8aa9dce28d 100644
--- a/core/modules/editor/js/editor.admin.js
+++ b/core/modules/editor/js/editor.admin.js
@@ -240,7 +240,7 @@
         }
 
         // The simple case: no wildcard in property value.
-        if (propertyValue.indexOf('*') === -1) {
+        if (!propertyValue.includes('*')) {
           if (
             universe.hasOwnProperty(tag) &&
             universe[tag].hasOwnProperty(key)
diff --git a/core/modules/layout_builder/js/layout-builder.js b/core/modules/layout_builder/js/layout-builder.js
index 4b5c0f6403c1..76b751c6ccf5 100644
--- a/core/modules/layout_builder/js/layout-builder.js
+++ b/core/modules/layout_builder/js/layout-builder.js
@@ -44,8 +44,7 @@
          */
         const toggleBlockEntry = (index, link) => {
           const $link = $(link);
-          const textMatch =
-            link.textContent.toLowerCase().indexOf(query) !== -1;
+          const textMatch = link.textContent.toLowerCase().includes(query);
           // Checks if a category is currently hidden.
           // Toggles the category on if so.
           if (
diff --git a/core/modules/views/js/ajax_view.js b/core/modules/views/js/ajax_view.js
index 5365ade4724c..c76e7073f570 100644
--- a/core/modules/views/js/ajax_view.js
+++ b/core/modules/views/js/ajax_view.js
@@ -69,7 +69,7 @@
 
     // If there are multiple views this might've ended up showing up multiple
     // times.
-    if (ajaxPath.constructor.toString().indexOf('Array') !== -1) {
+    if (ajaxPath.constructor.toString().includes('Array')) {
       ajaxPath = ajaxPath[0];
     }
 
diff --git a/core/modules/views/js/base.js b/core/modules/views/js/base.js
index 050a3b67427d..31a0147c4c0f 100644
--- a/core/modules/views/js/base.js
+++ b/core/modules/views/js/base.js
@@ -20,9 +20,8 @@
    */
   Drupal.Views.parseQueryString = function (query) {
     const args = {};
-    const pos = query.indexOf('?');
-    if (pos !== -1) {
-      query = query.substring(pos + 1);
+    if (query.includes('?')) {
+      query = query.substring(query.indexOf('?') + 1);
     }
     let pair;
     const pairs = query.split('&');
@@ -106,7 +105,7 @@
     }
     const chars = ['#', '?', '&'];
     for (let i = 0; i < chars.length; i++) {
-      if (href.indexOf(chars[i]) > -1) {
+      if (href.includes(chars[i])) {
         href = href.substr(0, href.indexOf(chars[i]));
       }
     }
diff --git a/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js
index 2829de963208..34edf52d533f 100644
--- a/core/modules/views_ui/js/views-admin.js
+++ b/core/modules/views_ui/js/views-admin.js
@@ -570,7 +570,7 @@
         // Search through the search texts in the form for matching text.
         this.options.forEach((option) => {
           function hasWord(word) {
-            return option.searchText.indexOf(word) !== -1;
+            return option.searchText.includes(word);
           }
 
           let found = true;
diff --git a/core/modules/views_ui/js/views_ui.listing.js b/core/modules/views_ui/js/views_ui.listing.js
index 24bafde92a2f..e58816d9c5b2 100644
--- a/core/modules/views_ui/js/views_ui.listing.js
+++ b/core/modules/views_ui/js/views_ui.listing.js
@@ -36,7 +36,7 @@
           sources.forEach((item) => {
             sourcesConcat += item.textContent;
           });
-          const textMatch = sourcesConcat.toLowerCase().indexOf(query) !== -1;
+          const textMatch = sourcesConcat.toLowerCase().includes(query);
           $(row).closest('tr').toggle(textMatch);
         }
 
-- 
GitLab