--- /dev/null
+/*
+ * 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();
+});
);
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 {
* 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', () => {
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');
- });
-});
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 {
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];