Skip to content

Commit 2377622

Browse files
authored
Merge pull request #36 from ooni/fix/auto-trailing-slash
Add a trailing slash automatically
2 parents 20be5ec + ed3d707 commit 2377622

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

components/submit/EditForm.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ export const EditForm = ({ oldEntry, error, onSubmit, onCancel, layout = 'column
2525
const categoryCode = formData.get('category_code')
2626
const today = new Date().toISOString().split('T')[0]
2727

28+
// Add a trailing slash to the URL
29+
// * if not already added by user
30+
// * if the URL doesn't contain a path component (e.g "https://ooni.org/blog/test-lists")
31+
let url = formData.get('url')
32+
if (!url.endsWith('/') && !url.match(/\..+\/.+/)) {
33+
url = url + '/'
34+
}
35+
2836
const newEntry = {
29-
url: formData.get('url'),
37+
url: url,
3038
category_code: categoryCode,
3139
date_added: oldEntry.date_added ?? today,
3240
source: oldEntry.source ?? defaultSource,

0 commit comments

Comments
 (0)