Skip to content

Commit

Permalink
chore: add regex validation to whole pages #442
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Dec 17, 2024
1 parent c9a1c8a commit 618261d
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
4 changes: 3 additions & 1 deletion pages/category/[id].vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { regexForCategoryIds } from '~/composables/useIdsResolver'
//
// Validators
//
definePageMeta({
validate({ params }) {
return typeof params.id === 'string' && /^[-\w:,]+$/.test(params.id)
return !!params.id && regexForCategoryIds.test(params.id.toString())
},
})
</script>
2 changes: 1 addition & 1 deletion pages/embedded/[p1]/[poiId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ definePageMeta({
return false
}
return regexForCategoryIds.test(params.p1.toString()) && regexForPOIIds.test(params.poiId.toString())
return !!params.p1 && !!params.poiId && regexForCategoryIds.test(params.p1.toString()) && regexForPOIIds.test(params.poiId.toString())
},
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion pages/embedded/[p1]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { regexForCategoryIds } from '~/composables/useIdsResolver'
//
definePageMeta({
validate: ({ params }) => {
return regexForCategoryIds.test(params.p1.toString())
return !!params.p1 && regexForCategoryIds.test(params.p1.toString())
},
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion pages/index/[p1]/[poiId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ definePageMeta({
return false
}
return regexForCategoryIds.test(params.p1.toString()) && regexForPOIIds.test(params.poiId.toString())
return !!params.p1 && !!params.poiId && regexForCategoryIds.test(params.p1.toString()) && regexForPOIIds.test(params.poiId.toString())
},
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion pages/index/[p1]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { regexForCategoryIds } from '~/composables/useIdsResolver'
//
definePageMeta({
validate: ({ params }) => {
return regexForCategoryIds.test(params.p1.toString())
return !!params.p1 && regexForCategoryIds.test(params.p1.toString())
},
})
</script>
Expand Down
5 changes: 2 additions & 3 deletions pages/poi/[id]/details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import type { ApiPoi } from '~/lib/apiPois'
import { headerFromSettings } from '~/lib/apiSettings'
import { getAsyncDataOrThrows } from '~/lib/getAsyncData'
import { siteStore as useSiteStore } from '~/stores/site'
import { regexForPOIIds } from '~/composables/useIdsResolver'
//
// Validators
//
definePageMeta({
validate({ params }) {
return (
typeof params.id === 'string' && /^[-\w:]+$/.test(params.id)
)
return !!params.id && regexForPOIIds.test(params.id.toString())
},
})
Expand Down
6 changes: 2 additions & 4 deletions pages/pois/[ids]/map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import MapPois from '~/components/Map/MapPois.vue'
import { type ApiPoiId, type ApiPois, getPois } from '~/lib/apiPois'
import { getAsyncDataOrThrows } from '~/lib/getAsyncData'
import { siteStore as useSiteStore } from '~/stores/site'
import { regexForCategoryIds } from '~/composables/useIdsResolver'
//
// Validators
//
definePageMeta({
validate({ params }) {
return (
typeof params.ids === 'string'
&& /^[-\w:,]+$/.test(params.ids)
)
return !!params.ids && regexForCategoryIds.test(params.ids.toString())
},
})
Expand Down

0 comments on commit 618261d

Please sign in to comment.