Skip to content

Commit 20d9a31

Browse files
committed
GH-2370: Improve validation of dataset graph names
1 parent 86c82e1 commit 20d9a31

File tree

1 file changed

+30
-13
lines changed
  • jena-fuseki2/jena-fuseki-ui/src/views/dataset

1 file changed

+30
-13
lines changed

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

Lines changed: 30 additions & 13 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>
@@ -122,22 +122,20 @@
122122
<div class="pt-2 pb-2">
123123
<div class="progress" style="height: 1.5rem;">
124124
<div
125-
:style="`width: ${uploadSucceededPercentage}%`"
126-
:aria-valuenow="uploadSucceededPercentage"
127-
:title="`${uploadSucceededCount}/${uploadCount}`"
128125
class="progress-bar"
129126
role="progressbar"
127+
:style="`width: ${uploadSucceededPercentage}%`"
128+
:aria-valuenow="uploadSucceededPercentage"
130129
aria-valuemin="0"
131130
aria-valuemax="100"
132131
>
133132
{{ uploadSucceededCount }}/{{ uploadCount }}
134133
</div>
135134
<div
136-
:style="`width: ${uploadFailedPercentage}%`"
137-
:aria-valuenow="uploadFailedPercentage"
138-
:title="`${uploadFailedCount}/${uploadCount}`"
139135
class="progress-bar bg-danger"
140136
role="progressbar"
137+
:style="`width: ${uploadFailedPercentage}%`"
138+
:aria-valuenow="uploadFailedPercentage"
141139
aria-valuemin="0"
142140
aria-valuemax="100"
143141
>
@@ -327,7 +325,8 @@ export default {
327325
}
328326
const params = (this.datasetGraphName && this.datasetGraphName !== '') ? `?graph=${this.datasetGraphName}` : ''
329327
const dataEndpoint = this.services['gsp-rw']['srv.endpoints'].find(endpoint => endpoint !== '') || ''
330-
return this.$fusekiService.getFusekiUrl(`/${this.datasetName}/${dataEndpoint}${params}`)
328+
const fusekiUrl = this.$fusekiService.getFusekiUrl(`/${this.datasetName}/${dataEndpoint}${params}`)
329+
return fusekiUrl
331330
},
332331
uploadCount () {
333332
if (!this.upload || !this.upload.files) {
@@ -418,15 +417,33 @@ export default {
418417
return this.validateGraphName() && this.validateFiles()
419418
},
420419
validateGraphName () {
421-
// No spaces allowed in graph names.
422-
const pattern = /^[^\s]+$/
423420
const graphName = this.$refs['dataset-graph-name'].value
424-
if (graphName === '' || pattern.test(graphName)) {
421+
// An empty graph name is OK.
422+
if (graphName === '') {
425423
this.graphNameClasses = ['form-control is-valid']
426424
return true
427425
}
428-
this.graphNameClasses = ['form-control is-invalid']
429-
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
430447
},
431448
validateFiles () {
432449
if (this.upload.files !== null && this.upload.files.length > 0) {

0 commit comments

Comments
 (0)