Skip to content

Commit 657c3b7

Browse files
committed
fix: handle string::npos case in a cleaner way and fix test
1 parent 98d5c1f commit 657c3b7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/machine-id/binding.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ namespace
5656
{
5757
return str;
5858
}
59-
6059
std::string result = str;
61-
result.erase(result.find_last_not_of(" \n\r\t") + 1);
60+
size_t from_right = result.find_last_not_of(" \n\r\t");
61+
if (from_right != std::string::npos)
62+
{
63+
result.erase(from_right + 1);
64+
}
6265
result.erase(0, result.find_first_not_of(" \n\r\t"));
6366
return result;
6467
}

packages/machine-id/src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('machine-id', function () {
1717
let id: string;
1818

1919
beforeEach(function () {
20-
const deviceId = getMachineId();
20+
const deviceId = getMachineId({ raw: true });
2121
assert(deviceId);
2222
id = deviceId;
2323
});

0 commit comments

Comments
 (0)