Skip to content

Commit

Permalink
chore: cast to bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevennevins committed Nov 29, 2023
1 parent 7786808 commit b12a85a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/FileSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ contract FileSystem is IFileSystem {
function hashFileNames(string[] calldata _fileNames) public pure returns (bytes32[] memory hashedPaths) {
uint256 length = _fileNames.length;
hashedPaths = new bytes32[](length);
bytes memory filename;
for (uint256 i; i < length; i++) {
if (bytes(_fileNames[i]).length == 0) revert InvalidFileName();
if (_containsForbiddenChars(_fileNames[i])) revert InvalidCharacter();
hashedPaths[i] = keccak256(bytes(_fileNames[i]));
filename = bytes(_fileNames[i]);
if (filename.length == 0) revert InvalidFileName();
if (_containsForbiddenChars(filename)) revert InvalidCharacter();
hashedPaths[i] = keccak256(filename);
}
}

Expand All @@ -159,11 +161,11 @@ contract FileSystem is IFileSystem {
/**
* @dev Checks if the given string contains any forbidden characters
*/
function _containsForbiddenChars(string calldata _stringToCheck) private pure returns (bool) {
function _containsForbiddenChars(bytes memory _stringToCheck) private pure returns (bool) {
uint256 length = bytes(_stringToCheck).length;
for (uint256 i; i < length; i++) {
for (uint256 j; j < CHARACTER_LENGTH; j++) {
if (bytes(_stringToCheck)[i] == bytes(FORBIDDEN_CHARS)[j]) {
if (_stringToCheck[i] == FORBIDDEN_CHARS[j]) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pragma solidity 0.8.23;

// Characters
uint256 constant CHARACTER_LENGTH = 18;
string constant FORBIDDEN_CHARS = ":/?#[]@!$&'()*+,;=";
bytes constant FORBIDDEN_CHARS = bytes(":/?#[]@!$&'()*+,;=");

0 comments on commit b12a85a

Please sign in to comment.