Repository navigation
fix(data): preserve KML fields declared as text - #3504
Conversation
Look up the local SchemaData reference before type inference so declared strings keep their values and padding.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| .and_then(|parent| parent.attribute("schemaUrl")) | ||
| .and_then(|url| url.strip_prefix('#')) | ||
| .is_some_and(|id| strings.contains(&(id, k))); | ||
| let text = if string { raw_text_of(&d) } else { data_text(&d, k) }; |
There was a problem hiding this comment.
Bug (medium confidence, about 50%). For a schema-declared string field, the value is now raw_text_of(&d), which keeps every character between the tags. The KML parser does no whitespace normalisation (read passes the text straight to xml::parse), so a pretty-printed file like this:
<SimpleData name="House">
12
</SimpleData>now reads as "\n 12\n" instead of "12". Before this change the same field was trimmed, and a schema-typed string field was not. The formatting indentation is not part of the data, so the padding the PR wants to keep (" 12 " inline) is mixed up with XML layout. The new test only covers inline padding, so it doesn't catch this.
Suggested direction: keep the raw text only when it is inline (no newline in it), or trim the leading and trailing line-break and indentation whitespace while keeping spaces. Add a test with a multi-line SimpleData value.
Category: bug
There was a problem hiding this comment.
Fixed in 601162b: whitespace at an end of the value is left out when it holds a line break, and kept otherwise. The new test reads an indented value, an inline padded one, a blank one and one with a line break inside.
| name == "string" && n.lookup_namespace_uri(prefix) == Some("http://www.w3.org/2001/XMLSchema") | ||
| } | ||
|
|
||
| /// Index local schema declarations so a field's type follows its own SchemaData reference. |
There was a problem hiding this comment.
The doc comment says a field's type "follows its own SchemaData reference", but the type is set per column for each geometry layer, not per placemark. string_keys is keyed by field name, and type_text_columns_keeping then keeps the whole column as text. So if one points layer has one placemark whose SchemaData declares House as string and another whose schema declares it int, the int values are also stored as text. Nothing is lost, but the doc overstates the rule, and the new test only covers separate layers (points vs lines), so this case is not tested.
Either say in the doc comment that the column is typed per layer, or add a test for the mixed-layer case and decide what it should produce.
Nit, left for the quality pass: schema_strings compares type exactly to "string", while explicit_string resolves the namespace prefix. A type="xs:string" or padded type would be treated differently.
Category: quality
There was a problem hiding this comment.
The comment says it now, and the new test has the mixed layer: the column is text, as a value can't lose anything that way. The prefixed type is left for the release quality pass.
Code reviewReviewed Bugs
Security
Performance
Quality
AGENTS.md
What I checked
Change sizeCompared: the whole PR against main (merge base fdf25d1 to PR head 87536ae).
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
| @@ -638,7 +668,16 @@ impl Reader { | |||
| let text = value.map(|v| if string { raw_text_of(&v) } else { data_text(&v, k) }).unwrap_or_default(); | |||
There was a problem hiding this comment.
This is the twin of the SimpleData path the PR changes, and it still has the bug the PR fixes there. For a <Data> whose <value> has an explicit xsi:type string, raw_text_of(&v) keeps every character between the tags. In a pretty-printed file such as
<Data name="House">
<value xsi:type="xs:string">
012
</value>
</Data>the value reads as "\n 012\n " rather than "012", so the indentation becomes data. The SimpleData branch now uses string_text to drop line breaks and indentation, and this branch should do the same. data_text already returns the raw text for description, so the suggestion keeps that case unchanged. This path predates the PR, but it is the same family, and the new SimpleData test does not cover it. A regression test with an indented <Data>/<value> should go with the fix.
Category: bug
There was a problem hiding this comment.
Kept as it is, on purpose. An explicit xsi:type string is what RustGIS's own writer puts on a text field's values (interop.rs), with no layout around them, so every character between the tags is the value: one that begins or ends with a line break would be changed by a round trip if it were trimmed here. A SimpleData value has no such mark, and RustGIS doesn't write them, so only there can a line break at an end be taken for a file's layout.
Code reviewBugs
Security
Performance
Quality
AGENTS.md
Already raised, left alone: 2 earlier concerns. The indentation thread is resolved by 601162b, and the mixed-layer thread was answered by the author with a doc change and a test. Confidence: the one bug is medium. Everything else is high confidence or a nit. Change sizeCompared with main (merge base fdf25d1 to PR head 601162b).
|
Summary
House, declaredstring, was read as whole numbers without a notice.SimpleDatafield that the schema itsSchemaDatanames declaresstringstays text, with its spelling and padding, but without the line breaks and indentation an indented file puts around it. One value declared so makes its layer's column text. Other fields' types are still taken from their values.string. Their number-like columns, read as numbers until now, are text. That is what the files say, and leading zeros and long ids survive.The desktop, the browser, the command line, Python and the phone read KML and KMZ through this code. The schema's declarations are indexed once a file, and no layer data is copied.
Testing
mainand passes here: a padded house number, a number that isn't declared, and another schema declaring the same nameint. A second covers an indented file and a layer whose schemas disagree.Housevalue as text, through a typed GeoPackage export.UI evidence
No visible UI change.
Related issue
Follow-up to #3203. Part of #1998.
Summary by CodeRabbit