File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ impl ConvertVariant for Variant {
27
27
target_type : VariantType ,
28
28
) -> Result < Cow < ' _ , Self > , String > {
29
29
match ( value. borrow ( ) , target_type) {
30
+ // Older files may not have their number types moved to 64-bit yet,
31
+ // which can cause problems. See issue #301.
32
+ ( Variant :: Int32 ( value) , VariantType :: Int64 ) => {
33
+ Ok ( Cow :: Owned ( ( i64:: from ( * value) ) . into ( ) ) )
34
+ }
35
+ ( Variant :: Float32 ( value) , VariantType :: Float64 ) => {
36
+ Ok ( Cow :: Owned ( ( f64:: from ( * value) ) . into ( ) ) )
37
+ }
30
38
( Variant :: Int32 ( value) , VariantType :: BrickColor ) => {
31
39
let narrowed: u16 = ( * value) . try_into ( ) . map_err ( |_| {
32
40
format ! ( "Value {} is not in the range of a valid BrickColor" , value)
Original file line number Diff line number Diff line change @@ -588,6 +588,7 @@ fn deserialize_properties<R: Read>(
588
588
DataType :: Enum ( _enum_name) => VariantType :: Enum ,
589
589
_ => unimplemented ! ( ) ,
590
590
} ;
591
+ log:: trace!( "property's read type: {xml_ty:?}, canonical type: {expected_type:?}" ) ;
591
592
592
593
let value = match value. try_convert ( expected_type) {
593
594
Ok ( value) => value,
Original file line number Diff line number Diff line change @@ -230,3 +230,36 @@ fn read_unique_id() {
230
230
) ) )
231
231
) ;
232
232
}
233
+
234
+ #[ test]
235
+ fn number_widening ( ) {
236
+ let _ = env_logger:: try_init ( ) ;
237
+ let document = r#"
238
+ <roblox version="4">
239
+ <Item class="IntValue" referent="Test">
240
+ <Properties>
241
+ <int name="Value">194</int>
242
+ </Properties>
243
+ </Item>
244
+ <Item class="NumberValue" referent="Test">
245
+ <Properties>
246
+ <float name="Value">1337</float>
247
+ </Properties>
248
+ </Item>
249
+ </roblox>
250
+ "# ;
251
+ let tree = crate :: from_str_default ( document) . unwrap ( ) ;
252
+
253
+ let int_value = tree. get_by_ref ( tree. root ( ) . children ( ) [ 0 ] ) . unwrap ( ) ;
254
+ assert_eq ! ( int_value. class, "IntValue" ) ;
255
+ assert_eq ! (
256
+ int_value. properties. get( "Value" ) ,
257
+ Some ( & Variant :: Int64 ( 194 ) )
258
+ ) ;
259
+ let float_value = tree. get_by_ref ( tree. root ( ) . children ( ) [ 1 ] ) . unwrap ( ) ;
260
+ assert_eq ! ( float_value. class, "NumberValue" ) ;
261
+ assert_eq ! (
262
+ float_value. properties. get( "Value" ) ,
263
+ Some ( & Variant :: Float64 ( 1337.0 ) )
264
+ ) ;
265
+ }
You can’t perform that action at this time.
0 commit comments