fix: trim collection name on save rather than on change (#2962)
* fix: trim collection name on save rather than on change * move trim to server
This commit is contained in:
@@ -74,7 +74,7 @@ const CollectionEdit = ({ collectionId, onSubmit }: Props) => {
|
||||
};
|
||||
|
||||
const handleNameChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setName(ev.target.value.trim());
|
||||
setName(ev.target.value);
|
||||
};
|
||||
|
||||
const handleChange = (color: string, icon: string) => {
|
||||
|
||||
@@ -1253,14 +1253,14 @@ describe("#collections.update", () => {
|
||||
expect(body.data.name).toBe(collection.name);
|
||||
});
|
||||
|
||||
it("allows editing from non-private to private collection", async () => {
|
||||
it("allows editing from non-private to private collection, and trims whitespace", async () => {
|
||||
const { user, collection } = await seed();
|
||||
const res = await server.post("/api/collections.update", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
id: collection.id,
|
||||
permission: null,
|
||||
name: "Test",
|
||||
name: " Test ",
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
|
||||
@@ -536,7 +536,7 @@ router.post("collections.update", auth(), async (ctx) => {
|
||||
let sharingChanged = false;
|
||||
|
||||
if (name !== undefined) {
|
||||
collection.name = name;
|
||||
collection.name = name.trim();
|
||||
}
|
||||
|
||||
if (description !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user