@@ -41,9 +41,13 @@ def parse_snippet(self, snippet_dict: Dict) -> Snippet:
4141 spdx_id : Optional [str ] = snippet_dict .get ("SPDXID" )
4242 file_spdx_id : Optional [str ] = snippet_dict .get ("snippetFromFile" )
4343 name : Optional [str ] = snippet_dict .get ("name" )
44+
4445 ranges : Dict = parse_field_or_log_error (logger , snippet_dict .get ("ranges" , []), self .parse_ranges , default = {})
45- byte_range : Tuple [int , int ] = ranges .get (RangeType .BYTE )
46- line_range : Optional [Tuple [int , int ]] = ranges .get (RangeType .LINE )
46+ byte_range : Optional [Tuple [Union [int , str ], Union [int , str ]]] = ranges .get (RangeType .BYTE )
47+ line_range : Optional [Tuple [Union [int , str ], Union [int , str ]]] = ranges .get (RangeType .LINE )
48+ byte_range = self .convert_range_from_str (byte_range )
49+ line_range = self .convert_range_from_str (line_range )
50+
4751 attribution_texts : List [str ] = snippet_dict .get ("attributionTexts" , [])
4852 comment : Optional [str ] = snippet_dict .get ("comment" )
4953 copyright_text : Optional [str ] = snippet_dict .get ("copyrightText" )
@@ -114,3 +118,15 @@ def validate_pointer_and_get_type(pointer: Dict) -> RangeType:
114118 if "offset" not in pointer and "lineNumber" not in pointer :
115119 raise ValueError ('Couldn\' t determine type of pointer: neither "offset" nor "lineNumber" provided as key.' )
116120 return RangeType .BYTE if "offset" in pointer else RangeType .LINE
121+
122+ @staticmethod
123+ def convert_range_from_str (_range : Tuple [Union [int , str ], Union [int , str ]]) -> Tuple [Union [int , str ], Union [int , str ]]:
124+ # XML does not support integers, so we have to convert from string (if possible)
125+ if not _range :
126+ return _range
127+
128+ if isinstance (_range [0 ], str ) and _range [0 ].isdigit ():
129+ _range = int (_range [0 ]), _range [1 ]
130+ if isinstance (_range [1 ], str ) and _range [1 ].isdigit ():
131+ _range = _range [0 ], int (_range [1 ])
132+ return _range
0 commit comments