From 5c4cbadae2f6bd3fb8b3aec6cdb49183387e785b Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Fri, 13 Dec 2024 05:57:51 +0100 Subject: [PATCH] check version string with regex --- report-viewer/src/App.vue | 4 ++-- report-viewer/src/model/Version.ts | 4 +++- report-viewer/src/views/OldVersionRedirectView.vue | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/report-viewer/src/App.vue b/report-viewer/src/App.vue index 58b62b9de..d97778be9 100644 --- a/report-viewer/src/App.vue +++ b/report-viewer/src/App.vue @@ -41,7 +41,7 @@ import { computed, ref } from 'vue' library.add(faMoon) library.add(faSun) -const newestVersion = ref(new Version(-1, -1, -1)) +const newestVersion = ref(Version.ERROR_VERSION) const isDemo = import.meta.env.MODE == 'demo' const hasShownToast = ref(sessionStorage.getItem('hasShownToast') == 'true') @@ -75,6 +75,6 @@ fetch('https://api.github.com/repos/jplag/JPlag/releases/latest') ) }) .catch(() => { - newestVersion.value = new Version(-1, -1, -1) + newestVersion.value = Version.ERROR_VERSION }) diff --git a/report-viewer/src/model/Version.ts b/report-viewer/src/model/Version.ts index a6fe306db..503e07566 100644 --- a/report-viewer/src/model/Version.ts +++ b/report-viewer/src/model/Version.ts @@ -8,6 +8,8 @@ export class Version { private readonly minor: number private readonly patch: number + public static readonly ERROR_VERSION = new Version(-1, -1, -1) + constructor(major: number, minor: number, patch: number) { this.major = major this.minor = minor @@ -40,7 +42,7 @@ export class Version { if (versionField) { return new Version(versionField.major, versionField.minor, versionField.patch) } - return new Version(-1, -1, -1) + return Version.ERROR_VERSION } } diff --git a/report-viewer/src/views/OldVersionRedirectView.vue b/report-viewer/src/views/OldVersionRedirectView.vue index cf60110ed..e41c1cea8 100644 --- a/report-viewer/src/views/OldVersionRedirectView.vue +++ b/report-viewer/src/views/OldVersionRedirectView.vue @@ -55,6 +55,9 @@ const props = defineProps({ }) const uploadedVersion = computed(() => { + if (!props.version.match(/^\d+\.\d+\.\d+$/)) { + return Version.ERROR_VERSION + } const parts = props.version.split('.').map(Number) return new Version(parts[0], parts[1], parts[2]) })