fix: disallow "/" in renamed directory and filenames

This commit is contained in:
ArielLeyva 2025-09-19 11:18:12 -04:00
parent e6c674b3c6
commit 69f5db9590
2 changed files with 17 additions and 1 deletions

View File

@ -16,6 +16,9 @@
@keyup.enter="submit" @keyup.enter="submit"
v-model.trim="name" v-model.trim="name"
/> />
<p class="invalid-name" v-if="!isValidName">
{{ $t("errors.invalidFileName") }}
</p>
</div> </div>
<div class="card-action"> <div class="card-action">
@ -31,6 +34,7 @@
@click="submit" @click="submit"
class="button button--flat" class="button button--flat"
type="submit" type="submit"
:disabled="!isValidName"
:aria-label="$t('buttons.rename')" :aria-label="$t('buttons.rename')"
:title="$t('buttons.rename')" :title="$t('buttons.rename')"
> >
@ -48,6 +52,8 @@ import url from "@/utils/url";
import { files as api } from "@/api"; import { files as api } from "@/api";
import { removePrefix } from "@/api/utils"; import { removePrefix } from "@/api/utils";
const INVALID_CHARACTERS = ["/"];
export default { export default {
name: "rename", name: "rename",
data: function () { data: function () {
@ -67,6 +73,9 @@ export default {
"isListing", "isListing",
]), ]),
...mapWritableState(useFileStore, ["reload", "preselect"]), ...mapWritableState(useFileStore, ["reload", "preselect"]),
isValidName() {
return !INVALID_CHARACTERS.some((char) => this.name.includes(char));
},
}, },
methods: { methods: {
...mapActions(useLayoutStore, ["closeHovers"]), ...mapActions(useLayoutStore, ["closeHovers"]),
@ -117,3 +126,9 @@ export default {
}, },
}; };
</script> </script>
<style scoped>
.invalid-name {
color: var(--red);
font-size: 0.9em;
}
</style>

View File

@ -57,7 +57,8 @@
"forbidden": "You don't have permissions to access this.", "forbidden": "You don't have permissions to access this.",
"internal": "Something really went wrong.", "internal": "Something really went wrong.",
"notFound": "This location can't be reached.", "notFound": "This location can't be reached.",
"connection": "The server can't be reached." "connection": "The server can't be reached.",
"invalidFileName": "The file or directory name is not valid."
}, },
"files": { "files": {
"body": "Body", "body": "Body",