Skip to content

Commit d3dca83

Browse files
committed
GH-2370: Improve validation of dataset graph names
1 parent d034081 commit d3dca83

File tree

1 file changed

+26
-7
lines changed
  • jena-fuseki2/jena-fuseki-ui/src/views/dataset

1 file changed

+26
-7
lines changed

jena-fuseki2/jena-fuseki-ui/src/views/dataset/Upload.vue

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
placeholder="Leave blank for default graph"
6161
/>
6262
<div class="invalid-feedback">
63-
Invalid graph name. Please remove any spaces.
63+
Invalid graph name. Please remove any spaces and encoded values.
6464
</div>
6565
</div>
6666
</div>
@@ -325,7 +325,8 @@ export default {
325325
}
326326
const params = (this.datasetGraphName && this.datasetGraphName !== '') ? `?graph=${this.datasetGraphName}` : ''
327327
const dataEndpoint = this.services['gsp-rw']['srv.endpoints'].find(endpoint => endpoint !== '') || ''
328-
return this.$fusekiService.getFusekiUrl(`/${this.datasetName}/${dataEndpoint}${params}`)
328+
const fusekiUrl = this.$fusekiService.getFusekiUrl(`/${this.datasetName}/${dataEndpoint}${params}`)
329+
return fusekiUrl
329330
},
330331
uploadCount () {
331332
if (!this.upload || !this.upload.files) {
@@ -416,15 +417,33 @@ export default {
416417
return this.validateGraphName() && this.validateFiles()
417418
},
418419
validateGraphName () {
419-
// No spaces allowed in graph names.
420-
const pattern = /^[^\s]+$/
421420
const graphName = this.$refs['dataset-graph-name'].value
422-
if (graphName === '' || pattern.test(graphName)) {
421+
// An empty graph name is OK.
422+
if (graphName === '') {
423423
this.graphNameClasses = ['form-control is-valid']
424424
return true
425425
}
426-
this.graphNameClasses = ['form-control is-invalid']
427-
return false
426+
// No spaces allowed in graph names.
427+
const pattern = /^\S+$/
428+
if (!pattern.test(graphName)) {
429+
this.graphNameClasses = ['form-control is-invalid']
430+
return false
431+
}
432+
// Only valid URIs allowed.
433+
try {
434+
new URL(graphName)
435+
} catch {
436+
this.graphNameClasses = ['form-control is-invalid']
437+
return false
438+
}
439+
// Encoded components are not allowed.
440+
if (decodeURI(graphName) !== decodeURIComponent(graphName)) {
441+
this.graphNameClasses = ['form-control is-invalid']
442+
return false
443+
}
444+
// If it reached this part, then it's a valid graph name.
445+
this.graphNameClasses = ['form-control is-valid']
446+
return true
428447
},
429448
validateFiles () {
430449
if (this.upload.files !== null && this.upload.files.length > 0) {

0 commit comments

Comments
 (0)