int toIndex = NumberOfLabels - 1;
int fromIndex = index - 1;
- for (int i = index - compressorIndex; i > 0; --i)
+ // if fromIndex and toIndex are the same, it means that "zero bits" are already in the correct place
+ // it happens for leading and trailing compression
+ if (fromIndex != toIndex)
{
- numbers[toIndex--] = numbers[fromIndex];
- numbers[fromIndex--] = 0;
+ for (int i = index - compressorIndex; i > 0; --i)
+ {
+ numbers[toIndex--] = numbers[fromIndex];
+ numbers[fromIndex--] = 0;
+ }
}
}
}
new object[] { "E:E:E:E:E:0:0:1", "E:E:E:E:E::1" },
new object[] { "E:E:E:E:E:0:2:2", "E:E:E:E:E:0:2:2" },
new object[] { "E:E:E:E:E:E:0:1", "E:E:E:E:E:E:0:1" },
+ new object[] { "::2:3:4:5:6:7:8", "0:2:3:4:5:6:7:8" },
+ new object[] { "1:2:3:4:5:6:7::", "1:2:3:4:5:6:7:0" },
new object[] { "::FFFF:192.168.0.1", "::FFFF:192.168.0.1" },
new object[] { "::FFFF:0.168.0.1", "::FFFF:0.168.0.1" },
new object[] { "::0.0.255.255", "::FFFF" },
[InlineData("1:0:0:1:0:0:1:1", "1::1:0:0:1:1")]
[InlineData("1:1:0:0:0:1:0:1", "1:1::1:0:1")]
[InlineData("1:0:0:0:1:0:1:1", "1::1:0:1:1")]
+ [InlineData("::2:3:4:5:6:7:8", "0:2:3:4:5:6:7:8")]
+ [InlineData("1:2:3:4:5:6:7::", "1:2:3:4:5:6:7:0")]
public void UriIPv6Host_CompressionRangeSelection_Success(string address, string expected)
{
ParseIPv6Address(address, expected);