Skip to content

fix(data): preserve KML fields declared as text - #3504

Merged
Mavrick-F merged 2 commits into
opengeos:mainfrom
Mavrick-F:fix/kml-declared-text
Dec 1, 2026
Merged

Mavrick-F merged 2 commits into
opengeos:mainfrom
Mavrick-F:fix/kml-declared-text

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The KML reader used a file's schema for field names and took their types from the values. A published permit file's House, declared string, was read as whole numbers without a notice.
  • A SimpleData field that the schema its SchemaData names declares string stays 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.
  • What users will see: many KML files declare every field 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

  • The new test fails on main and passes here: a padded house number, a number that isn't declared, and another schema declaring the same name int. A second covers an indented file and a layer whose schemas disagree.
  • The published permit file keeps all 10,008 drawable rows and every House value as text, through a typed GeoPackage export.
  • The data suite (2,176 tests) and clippy. The fork's full Linux gate passed on this commit: run.

UI evidence

No visible UI change.

Related issue

Follow-up to #3203. Part of #1998.

Summary by CodeRabbit

  • Bug Fixes
    • KML fields explicitly declared as strings now retain numeric-looking text and intentional whitespace, including internal line breaks.
    • String handling applies only when a value matches a local schema declaration; other fields continue to use existing parsing and numeric inference.

Look up the local SchemaData reference before type inference so declared strings keep their values and padding.
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

KML reading now indexes local string-field declarations and passes the index through document traversal. Matching SimpleData values use string-specific whitespace handling. Other values retain the existing parsing path. Tests cover schema matching and type inference.

Changes: KML schema-aware value parsing

Layer / File(s) Summary
Index and apply schema string types
crates/data/src/kml.rs
The reader indexes local SimpleField declarations with type string and passes the index through document traversal. Matching SimpleData values use string-specific whitespace handling, except for description. Other values retain the existing parsing path. Tests cover padded and numeric-looking strings, indentation, unmatched and integer-typed fields, and column typing by geometry layer.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • opengeos/RustGIS#3203: Both changes define how KML schema declarations affect field types in crates/data/src/kml.rs.

Suggested reviewers: giswqs

Merge Risk: Minimal · up to 60116

KML fields declared as text now keep their original spelling and padding, while undeclared fields still get their types from their values. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(data): preserve KML fields declared as text" matches the main change in the changeset. The PR makes KML reading keep a SimpleData value as text when its SchemaData references a local sc…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the template's Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change, the reason for it, and the user-visible effect. Testing names a new t…
Full details: Title check

Explanation

The title "fix(data): preserve KML fields declared as text" matches the main change in the changeset. The PR makes KML reading keep a SimpleData value as text when its SchemaData references a local schema that declares the field as string. The title is specific, concise, and uses a conventional commit prefix.

Full details: Description check

Explanation

The description follows the template's Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change, the reason for it, and the user-visible effect. Testing names a new test, a regression check against main, a typed GeoPackage export check, the data suite, and clippy. UI evidence correctly states no visible UI change. Related issue names #3203 and #1998. The template's Testing guidance asks for how the change was verified, and the author provided that. Minor gap: the author's Linux CI run link points to a different run ID (46552471476) than the one in the objectives (46542570751). The reviewer should confirm which link is correct. This does not make the description incomplete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit reads each schema line,
And finds the fields declared as string.
It keeps their padding where it belongs,
While other values follow their path.
The KML rows sort into place,
And carrots wait beside the case.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: aa0a8e54-9cfa-490b-8ca3-caeb253f43fd
Commits

Reviewing files that changed from the base of the PR and between 87536ae and 601162b.

Files selected for processing: 1

  • crates/data/src/kml.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Comment thread crates/data/src/kml.rs Outdated
.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) };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/data/src/kml.rs Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

Reviewed crates/data/src/kml.rs (+56/−7) against pr-context/AGENTS.md. Both inline comments are posted. No prior review threads exist on this PR, so none were left alone.

Bugs

  • Pretty-printed values keep their indentation (kml.rs:664). Schema-declared string SimpleData values use raw_text_of, which keeps all whitespace. A multi-line value such as <SimpleData name="House">\n 12\n</SimpleData> now reads as "\n 12\n", not "12". The new test covers only inline padding. Confidence: medium (about 50%). Category: bug.

Security

  • None found.

Performance

  • None found. The extra schema_strings pass is one linear walk, and lookups are O(1). Memory is bounded by the input document.

Quality

  • The doc comment overstates the typing rule (kml.rs:236). Types are set per column for each geometry layer, not per placemark. In a points layer that mixes two schemas that disagree about House, the int values also become text. The new test covers only separate layers. Confidence: medium. Category: quality.
  • Exact type match (kml.rs:241). schema_strings compares type to "string" exactly, but explicit_string resolves namespace prefixes. Nit, confidence: low. Category: quality.
  • Intended behaviour change, not flagged inline. Number-like columns in files whose schemas declare string now read as text. This follows the PR's stated intent, but it changes expression results and numeric symbology for those files. Confidence: high that it happens. Category: quality (note only).

AGENTS.md

  • None found. I checked the non-test code for unwrap, expect, panic and indexing, and found none. The new code uses get() and strip_prefix. There is no platform-specific code, so the wasm build is not affected. No command, layer or project-save change, so no schema or fixture update is needed.

What I checked

  • KML read routes. Every KML and KMZ read goes through io.rs:310 and io.rs:329, which call kml::read. The KMZ path shares the same parser, so there is no separate twin to update. GPX, GeoRSS and GML have no schema-typed string path.
  • Writer round trip. interop.rs declares each field type="string" but writes values as <Data> entries, which this change does not touch. Round trips of RustGIS-written files are unaffected.
  • Lossy-input notices. The new test asserts no notices on clean input. No new loss is introduced.

Change size

Compared: the whole PR against main (merge base fdf25d1 to PR head 87536ae).

Measure Value
Files changed 1 (added 0, modified 1, removed 0, renamed 0)
Size before 78.8 KB
Size after 81.7 KB
Total size change +2.9 KB
Path Before After Change
crates/data/src/kml.rs 78.8 KB 81.7 KB +2.9 KB

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3504/
Web app https://preview.rustgis.app/pr-3504/app/
Commit 601162b

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 preview label (once per commit).

Comment thread crates/data/src/kml.rs
@@ -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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • crates/data/src/kml.rs:668, medium confidence (~60%): the <Data>/<value> path with an explicit xsi:type string still uses raw_text_of, so pretty-printed indentation and line breaks become part of the value. The SimpleData branch fixes this in this PR, but this twin does not. The path predates the PR, but it is in the same family and the new tests don't cover it. Inline comment posted with a suggested fix and a regression-test request.
  • The earlier indentation thread is fixed in 601162b. I checked string_text for inline padding, indented values, whitespace-only values and multi-byte text, and found no panic or wrong output.

Security

  • None found. The new code uses bounded descendant scans, no recursion, and no unchecked slicing (raw.get with unwrap_or_default).

Performance

  • None significant. The schema set is built once per file and holds borrowed &strs, so no layer data is copied. string_text allocates twice per value, which is negligible.

Quality

  • Nit, left for the release quality pass: schema_strings compares type exactly to "string", so a prefixed xs:string is not matched, unlike explicit_string. This was already raised and answered, so I did not repost it.
  • Nit, not posted inline: the from/to logic in string_text is correct but dense. A short comment on the whitespace-only case would help.

AGENTS.md

  • No rule break found. The type change is not a loss, so no notice is required. The saved-project schema rule does not apply, since KML is read, not saved as a project. The PR body states the surfaces reached, and the change is plain Rust with nothing platform-specific, so wasm is unaffected.

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 size

Compared with main (merge base fdf25d1 to PR head 601162b).

Measure Value
Files changed 1 (0 added, 1 modified, 0 removed, 0 renamed)
Size before 78.8 KB
Size after 83.8 KB
Total size change +5.0 KB
Path Before After Change
crates/data/src/kml.rs 78.8 KB 83.8 KB +5.0 KB

@Mavrick-F
Mavrick-F added this pull request to the merge queue Dec 1, 2026
Merged via the queue into opengeos:main with commit 0e0d718 Dec 1, 2026
30 checks passed
@Mavrick-F
Mavrick-F deleted the fix/kml-declared-text branch December 1, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant