Skip to content

Commit

Permalink
check version string with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Dec 13, 2024
1 parent 0c1f09e commit 5c4cbad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions report-viewer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
})
</script>
4 changes: 3 additions & 1 deletion report-viewer/src/model/Version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down
3 changes: 3 additions & 0 deletions report-viewer/src/views/OldVersionRedirectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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])
})
Expand Down

0 comments on commit 5c4cbad

Please sign in to comment.