Skip to content

Commit bb3af31

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

File tree

1 file changed

+29
-6
lines changed
  • jena-fuseki2/jena-fuseki-ui/src/views/dataset

1 file changed

+29
-6
lines changed

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

Lines changed: 29 additions & 6 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>
@@ -416,15 +416,38 @@ export default {
416416
return this.validateGraphName() && this.validateFiles()
417417
},
418418
validateGraphName () {
419-
// No spaces allowed in graph names.
420-
const pattern = /^[^\s]+$/
421419
const graphName = this.$refs['dataset-graph-name'].value
422-
if (graphName === '' || pattern.test(graphName)) {
420+
// An empty graph name is OK.
421+
if (graphName === '') {
423422
this.graphNameClasses = ['form-control is-valid']
424423
return true
425424
}
426-
this.graphNameClasses = ['form-control is-invalid']
427-
return false
425+
// No spaces allowed in graph names.
426+
const pattern = /^\S+$/
427+
if (!pattern.test(graphName)) {
428+
this.graphNameClasses = ['form-control is-invalid']
429+
return false
430+
}
431+
// Only valid URIs allowed.
432+
try {
433+
new URL(graphName)
434+
} catch {
435+
this.graphNameClasses = ['form-control is-invalid']
436+
return false
437+
}
438+
// Encoded components are not allowed.
439+
try {
440+
if (decodeURI(graphName) !== decodeURIComponent(graphName)) {
441+
this.graphNameClasses = ['form-control is-invalid']
442+
return false
443+
}
444+
} catch {
445+
this.graphNameClasses = ['form-control is-invalid']
446+
return false
447+
}
448+
// If it reached this part, then it's a valid graph name.
449+
this.graphNameClasses = ['form-control is-valid']
450+
return true
428451
},
429452
validateFiles () {
430453
if (this.upload.files !== null && this.upload.files.length > 0) {

0 commit comments

Comments
 (0)