Skip to content
This repository
Browse code

ready for testing BOM defuser

  • Loading branch information...
commit a8ce2012c1314f1387569ce04ca0cc8a57f8b835 1 parent 5de8602
Peter Ohler authored

Showing 2 changed files with 24 additions and 9 deletions. Show diff stats Hide diff stats

  1. +4 0 .travis.yml
  2. +20 9 ext/ox/ox.c
4 .travis.yml
... ... @@ -1,4 +1,5 @@
1 1 #language: ruby
  2 +
2 3 rvm:
3 4 - 1.8.7
4 5 - 1.9.2
@@ -9,6 +10,9 @@ rvm:
9 10 - ree
10 11 - ruby-head
11 12
  13 +env:
  14 + - JRUBY_OPTS="--1.8 -Xcext.enabled=true"
  15 +
12 16 script:
13 17 - gem build ox.gemspec
14 18 - gem install ox-*
29 ext/ox/ox.c
@@ -131,8 +131,16 @@ static VALUE xsd_date_sym;
131 131
132 132 #if HAS_ENCODING_SUPPORT
133 133 rb_encoding *ox_utf8_encoding = 0;
  134 +static rb_encoding *ox_utf16le_encoding = 0;
  135 +static rb_encoding *ox_utf16be_encoding = 0;
  136 +static rb_encoding *ox_utf32le_encoding = 0;
  137 +static rb_encoding *ox_utf32be_encoding = 0;
134 138 #else
135 139 void *ox_utf8_encoding = 0;
  140 +static void *ox_utf16le_encoding = 0;
  141 +static void *ox_utf16be_encoding = 0;
  142 +static void *ox_utf32le_encoding = 0;
  143 +static void *ox_utf32be_encoding = 0;
136 144 #endif
137 145
138 146 struct _Options ox_default_options = {
@@ -166,40 +174,39 @@ defuse_bom(char *xml, Options options) {
166 174 options->rb_enc = ox_utf8_encoding;
167 175 xml += 3;
168 176 } else {
169   - // TBD error
  177 + rb_raise(rb_eArgError, "Invalid BOM in XML string.\n");
170 178 }
171 179 break;
172 180 case 0xFE: /* UTF-16BE */
173 181 if (0xFF == (uint8_t)xml[1]) {
174   - // TBD options->rb_enc = ox_utf16be_encoding;
  182 + options->rb_enc = ox_utf16be_encoding;
175 183 xml += 2;
176 184 } else {
177   - // TBD error
  185 + rb_raise(rb_eArgError, "Invalid BOM in XML string.\n");
178 186 }
179 187 break;
180 188 case 0xFF: /* UTF-16LE or UTF-32LE*/
181 189 if (0xFE == (uint8_t)xml[1]) {
182 190 if (0x00 == (uint8_t)xml[2] && 0x00 == (uint8_t)xml[3]) {
183   - // TBD options->rb_enc = ox_utf32le_encoding;
  191 + options->rb_enc = ox_utf32le_encoding;
184 192 xml += 4;
185 193 } else {
186   - // TBD options->rb_enc = ox_utf16le_encoding;
  194 + options->rb_enc = ox_utf16le_encoding;
187 195 xml += 2;
188 196 }
189 197 } else {
190   - // TBD error
  198 + rb_raise(rb_eArgError, "Invalid BOM in XML string.\n");
191 199 }
192 200 break;
193 201 case 0x00: /* UTF-32BE */
194 202 if (0x00 == (uint8_t)xml[1] && 0xFE == (uint8_t)xml[2] && 0xFF == (uint8_t)xml[3]) {
195   - // TBD options->rb_enc = ox_utf32be_encoding;
  203 + options->rb_enc = ox_utf32be_encoding;
196 204 xml += 4;
197 205 } else {
198   - // TBD error
  206 + rb_raise(rb_eArgError, "Invalid BOM in XML string.\n");
199 207 }
200 208 break;
201 209 default:
202   - // TBD error, not supported
203 210 break;
204 211 }
205 212 return xml;
@@ -853,6 +860,10 @@ void Init_ox() {
853 860 rb_define_module_function(Ox, "cache8_test", cache8_test, 0);
854 861 #if HAS_ENCODING_SUPPORT
855 862 ox_utf8_encoding = rb_enc_find("UTF-8");
  863 + ox_utf16le_encoding = rb_enc_find("UTF-16LE");
  864 + ox_utf16be_encoding = rb_enc_find("UTF-16BE");
  865 + ox_utf32le_encoding = rb_enc_find("UTF-32LE");
  866 + ox_utf32be_encoding = rb_enc_find("UTF-32BE");
856 867 #endif
857 868 }
858 869

0 comments on commit a8ce201

Please sign in to comment.
Something went wrong with that request. Please try again.