Skip to content

Commit

Permalink
Format and test limited encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Jan 11, 2025
1 parent e05471a commit f53e3aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ext/ox/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,14 @@ static void read_instruction(PInfo pi) {
pi->pcb->instruct(pi, target, attrs.head, content_ptr);
}
} else {
for (Attr a = attrs.head; a < attrs.tail; a++) {
if (0 == strcasecmp(a->name, "encoding")) {
strncpy(pi->options->encoding, a->value, sizeof(pi->options->encoding) - 1);
pi->options->encoding[sizeof(pi->options->encoding) - 1] = '\0';
pi->options->rb_enc = rb_enc_find(a->value);
break;
}
}
for (Attr a = attrs.head; a < attrs.tail; a++) {
if (0 == strcasecmp(a->name, "encoding")) {
strncpy(pi->options->encoding, a->value, sizeof(pi->options->encoding) - 1);
pi->options->encoding[sizeof(pi->options->encoding) - 1] = '\0';
pi->options->rb_enc = rb_enc_find(a->value);
break;
}
}
}
attr_stack_cleanup(&attrs);
if (content_ptr != content) {
Expand Down
8 changes: 8 additions & 0 deletions test/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,14 @@ def dump_and_load(obj, trace=false, circular=false)
end
loaded
end

def test_limit_encoding
Ox.default_options = $ox_object_options
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><doc><name>Martin</name></doc>".encode('ASCII-8BIT')
enc = Ox.load(xml, mode: :limited).locate('name').first.text.encoding
assert_equal('UTF-8', enc.to_s)
end

end

class Bag
Expand Down

0 comments on commit f53e3aa

Please sign in to comment.