Skip to content

Commit

Permalink
Fix subtle bug in decoding multiple numbers
Browse files Browse the repository at this point in the history
We shouldn't have done `TrimStart` on the `id`.
  • Loading branch information
aradalvand committed Aug 7, 2023
1 parent b0ddd24 commit 03d4107
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Sqids/Sqids.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>

<PackageId>Sqids</PackageId>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<Description>Official .NET port of Sqids. Generate short YouTube-looking IDs from numbers.</Description>
<PackageTags>Sqids;ID-generator;number-obfuscator;YouTube-ID</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/sqids/sqids-dotnet/main/icon.png</PackageIconUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Sqids/SqidsEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public IReadOnlyList<int> Decode(ReadOnlySpan<char> id)

var separatorIndex = id.IndexOf(separator);
var chunk = separatorIndex == -1 ? id : id[..separatorIndex]; // NOTE: The first part of `id` to the left of the separator is the number that we ought to decode.
id = id[chunk.Length..].TrimStart(separator); // NOTE: The `id` for the next iteration would exclude the current `chunk` (and also any following comma, if there is one)
id = separatorIndex == -1 ? string.Empty : id[(separatorIndex + 1)..]; // NOTE: Everything to the right of the separator will be `id ` for the next iteration

if (chunk.IsEmpty)
continue;
Expand Down

0 comments on commit 03d4107

Please sign in to comment.