fix dupeAndUnescape return value
This commit is contained in:
parent
088638661a
commit
c6524ff1d3
10
src/xml.zig
10
src/xml.zig
|
@ -654,7 +654,7 @@ fn dupeAndUnescape(alloc: Allocator, text: []const u8) ![]const u8 {
|
|||
// This error is not strictly true, but we need to match one of the items
|
||||
// from the error set provided by the other stdlib calls at the calling site
|
||||
if (!alloc.resize(str, j)) return error.OutOfMemory;
|
||||
return str;
|
||||
return str[0..j];
|
||||
}
|
||||
|
||||
test "dupeAndUnescape" {
|
||||
|
@ -662,8 +662,12 @@ test "dupeAndUnescape" {
|
|||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
||||
try testing.expectEqualSlices(u8, "test", try dupeAndUnescape(alloc, "test"));
|
||||
try testing.expectEqualSlices(u8, "a<b&c>d\"e'f<", try dupeAndUnescape(alloc, "a<b&c>d"e'f<"));
|
||||
const duped = try dupeAndUnescape(testing.allocator, "test");
|
||||
defer testing.allocator.free(duped);
|
||||
try testing.expectEqualSlices(u8, "test", duped);
|
||||
const duped2 = try dupeAndUnescape(testing.allocator, "a<b&c>d"e'f<");
|
||||
defer testing.allocator.free(duped2);
|
||||
try testing.expectEqualSlices(u8, "a<b&c>d\"e'f<", duped2);
|
||||
try testing.expectError(error.InvalidEntity, dupeAndUnescape(alloc, "python&"));
|
||||
try testing.expectError(error.InvalidEntity, dupeAndUnescape(alloc, "python&&"));
|
||||
try testing.expectError(error.InvalidEntity, dupeAndUnescape(alloc, "python&test;"));
|
||||
|
|
Loading…
Reference in New Issue
Block a user