]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17174 Changing regex conditions to fix security hotspot issues
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>
Mon, 15 Aug 2022 09:22:12 +0000 (11:22 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 16 Aug 2022 20:03:06 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/web-api/__tests__/utils-test.ts [new file with mode: 0644]
server/sonar-web/src/main/js/apps/web-api/utils.ts
server/sonar-web/src/main/js/helpers/__tests__/strings-test.ts
server/sonar-web/src/main/js/helpers/dates.ts
server/sonar-web/src/main/js/helpers/strings.ts

diff --git a/server/sonar-web/src/main/js/apps/web-api/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/web-api/__tests__/utils-test.ts
new file mode 100644 (file)
index 0000000..66d248a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+import { parseVersion } from '../utils';
+
+it('should test parseVersion is working as expected', () => {
+  expect(parseVersion('foo')).toBeUndefined();
+  expect(parseVersion('9.6')).toEqual({ major: 9, minor: 6 });
+  expect(parseVersion('9.6.2')).toEqual({ major: 9, minor: 6 });
+  expect(parseVersion('9.6.alpha')).toEqual({ major: 9, minor: 6 });
+  expect(parseVersion('9')).toBeUndefined();
+});
index e6abb0b46dfed49bb34d94a9f47798a5ba8c3d27..e35a5540ffee1291f5134423c997bbd1cd40637a 100644 (file)
@@ -81,7 +81,7 @@ export const serializeQuery = memoize(
 );
 
 export function parseVersion(version: string) {
-  const match = /(\d+)\.(\d+)/.exec(version);
+  const match = /(\d{1,5})\.(\d{1,5})/.exec(version);
   if (match) {
     return { major: Number(match[1]), minor: Number(match[2]) };
   } else {
index a25778883c08f5e9c8f5f58cbe590264960746e1..7eb89b9d88a3f9274afd3d1598877964b88b9fd3 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { decodeJwt, latinize, slugify } from '../strings';
+import { decodeJwt, latinize } from '../strings';
 
 describe('#decodeJwt', () => {
   it('should correctly decode a jwt token', () => {
@@ -49,11 +49,3 @@ describe('#latinize', () => {
     expect(latinize('ASDFGhjklQWERTz')).toBe('ASDFGhjklQWERTz');
   });
 });
-
-describe('#slugify', () => {
-  it('should transform text into a slug', () => {
-    expect(slugify('Luke Sky&Walker')).toBe('luke-sky-and-walker');
-    expect(slugify('tèst_:-ng><@')).toBe('test-ng');
-    expect(slugify('my-valid-slug-1')).toBe('my-valid-slug-1');
-  });
-});
index 8f6abea0a78f5a57ed3be7bf9ff6465124e6eeb8..5840f36bde431c030254f8310f3181571177539d 100644 (file)
@@ -38,7 +38,8 @@ export function toShortNotSoISOString(rawDate: ParsableDate): string {
 
 export function toNotSoISOString(rawDate: ParsableDate): string {
   const date = parseDate(rawDate);
-  return date.toISOString().replace(/\..+Z$/, '+0000');
+  const dateWithoutZone = date.toISOString().split('.')[0];
+  return dateWithoutZone + '+0000';
 }
 
 export function isValidDate(date: Date): boolean {
index 4099ce4e19cea261b75f15f2ddd2f8e6970fa4ae..82d791ba42df66e57957acea5ec6b3b314bcf27b 100644 (file)
@@ -408,18 +408,6 @@ export function latinize(str: string): string {
   return str.replace(/[^\u0000-\u007E]/g, a => diacriticsMap[a] || a);
 }
 
-// Inspired from https://github.com/SonarSource/sonar-enterprise/blob/master/sonar-core/src/main/java/org/sonar/core/util/Slug.java
-export function slugify(text: string) {
-  return latinize(text.trim().toLowerCase())
-    .replace(/&/g, '-and-') // Replace & with 'and'
-    .replace(/[^\w-]+/g, '-') // Replace all non-word chars with dash
-    .replace(/\s+/g, '-') // Replace whitespaces with dash
-    .replace(/[·/_,:;]/g, '-') // Replace special chars with dash
-    .replace(/--+/g, '-') // Replace multiple dash with single dash
-    .replace(/^-+/, '') // Remove heading dash
-    .replace(/-+$/, ''); // Remove trailing dash
-}
-
 export function decodeJwt(token: string) {
   const segments = token.split('.');
   const base64Url = segments.length > 1 ? segments[1] : segments[0];