Skip to content

Commit b4255bd

Browse files
authored
Merge pull request #49 from rmrk-team/trim-recipient-whitespace-and-validate
Invalidate SEND with space in recipient, but also remove any whitespa…
2 parents 169a177 + f6e4840 commit b4255bd

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"cli:run-listener": "ts-node --project tsconfig.cli.json cli/run-listener.ts",
3838
"cli:metadata": "ts-node --project tsconfig.cli.json cli/metadata.ts",
3939
"test": "jest --silent",
40+
"test:watch": "jest --watch --silent",
4041
"test:coverage": "jest --coverage --coverageDirectory='coverage'",
4142
"prepublishOnly": "yarn build"
4243
},

src/rmrk1.0.0/classes/nft.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class NFT {
104104
}
105105
return `${PREFIX}::${
106106
OP_TYPES.SEND
107-
}::${VERSION}::${this.getId()}::${recipient}`;
107+
}::${VERSION}::${this.getId()}::${recipient.replace(/\\s/g, "")}`;
108108
}
109109

110110
// @todo build this out, maybe data type?

src/tools/validate-remark.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ export const validateSend = (remark: string): any => {
145145

146146
try {
147147
validateBase(remark, OP_TYPES.SEND);
148+
if (/\s/g.test(recipient)) {
149+
throw new Error(
150+
"Invalid remark - No whitespaces are allowed in recipient"
151+
);
152+
}
148153
return assert({ id, recipient }, SENDStruct);
149154
} catch (error) {
150155
throw new Error(

test/utils/validate-send.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { validateNFT, validateSend } from "../../src/tools/validate-remark";
2+
3+
describe("validation: validateSend", () => {
4+
it("should be valid send", () => {
5+
const remark =
6+
"RMRK::SEND::1.0.0::6802213-24d573f4dfa1d7fd33-KAN-KANS-0000000000000001::dfsfsd dfsfd";
7+
8+
expect(() => validateSend(remark)).toThrowError(
9+
"Invalid remark - No whitespaces are allowed in recipient"
10+
);
11+
12+
expect(() => validateSend(remark.replace(/\s/g, ""))).not.toThrow();
13+
});
14+
});

0 commit comments

Comments
 (0)