minio-dart
minio-dart copied to clipboard
listBuckets assumes XML type but type is not guaranteed
When parsing the XML results for providers like Backblaze it is not guaranteed that XML is going to be of type XmlElement. In my case there were XmlText objects. Because of this, it would throw a parsing error.
3.5.5 code in the listBuckets() function in minio.dart line 486. return bucketsNode.children .map((n) => Bucket.fromXml(n as XmlElement)) .toList();
Notice it assumes the type to be XmlElement as parses it as such but that is not guaranteed. Below is a change I suggest which avoids throwing errors by checking the type and not relying on type assumption:
List<Bucket> results = <Bucket>[]; for (xml.XmlNode node in bucketsNode.children) { if (node is xml.XmlElement) { results.add(Bucket.fromXml(node as XmlElement)); } }
Im sure there is a more professional and elegant way to write the code than what I've written, but without type safety I need to fork your code with this change or things break with BackBlaze. Thanks!