From 07d05d0a2613b2ebef9a5b6c8c3cf3ea6d905833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 18 May 2021 15:45:14 +0200 Subject: [PATCH] MOBILE-3615 url: Fix docs url release number --- src/core/services/sites.ts | 15 +++++++++++++++ src/core/services/utils/url.ts | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index f1a414f8f..299be92e0 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -668,6 +668,21 @@ export class CoreSitesProvider { return ''; } + /** + * Returns the major release number from site release info. + * + * @param rawRelease Raw release info text. + * @return Major release number or empty. + */ + getMajorReleaseNumber(rawRelease: string): string { + const matches = rawRelease.match(/^\d+(\.\d+)?/); + if (matches) { + return matches[0]; + } + + return ''; + } + /** * Saves a site in local DB. * diff --git a/src/core/services/utils/url.ts b/src/core/services/utils/url.ts index 5b36f6c31..2f7cd0736 100644 --- a/src/core/services/utils/url.ts +++ b/src/core/services/utils/url.ts @@ -20,6 +20,7 @@ import { CoreConstants } from '@/core/constants'; import { makeSingleton } from '@singletons'; import { CoreUrl } from '@singletons/url'; import { CoreApp } from '@services/app'; +import { CoreSites } from '@services/sites'; /* * "Utils" service with helper functions for URLs. @@ -233,7 +234,8 @@ export class CoreUrlUtilsProvider { let docsUrl = 'https://docs.moodle.org/en/' + page; if (typeof release != 'undefined') { - const version = release.substr(0, 3).replace('.', ''); + const version = CoreSites.getMajorReleaseNumber(release).replace('.', ''); + // Check is a valid number. if (Number(version) >= 24) { // Append release number.