Skip to content

[Bug]: A CSV in Latin-1 (Windows-1252) can't be opened ("is not UTF-8 text") #1303

Closed

Description

@elpidioassinaturas

Before you start

  • I searched the existing issues and did not find a duplicate.
  • This is a bug report, not a usage question.

What happened?

A CSV in Latin-1 (or Windows-1252) can't be opened: Add Data refuses the whole file as soon as one byte isn't UTF-8.

amostra_latin1.csv is not UTF-8 text

Without x/y (as a table), the message is amostra_latin1.csv: i/o: stream did not contain valid UTF-8. Inside a zip, the archive is refused: no Shapefile or other vector data in the archive could be read: cnes_estabelecimentos.csv (cnes_estabelecimentos.csv is not UTF-8 text).

Many public data sources still publish in Latin-1. In Brazil these include DATASUS (Ministry of Health), INEP (education), TSE (elections) and the federal transparency portal. A single accented name (SÃO JOSÉ) or a non-breaking space in a phone number is enough to refuse a file of 640,000 rows. The case behind this report is the national registry of health facilities (CNES), whose CSV carries latitude and longitude for each facility.

The check is std::str::from_utf8 in rustgis_data::io::read_bytes ("csv" | "tsv" | "txt" => read_csv(text()?, …)), and the table path goes through a UTF-8 reader too. RustGIS already decodes Latin-1 elsewhere: .dbf files through encoding_rs, MapInfo MIF/MID by their charset (mapinfo.rs), and older OGC servers' XML (ogc_info.rs).

Steps to reproduce

  1. Download https://s3.sa-east-1.amazonaws.com/ckan.saude.gov.br/CNES/cnes_estabelecimentos_csv.zip (57 MB; a semicolon-separated CSV in Latin-1).
  2. In rustgis-cli, run layer.addUrl (or layer.addData on the zip) with {"x": "NU_LONGITUDE", "y": "NU_LATITUDE", "delimiter": ";"}. The zip is refused.
  3. Extract the CSV, or keep only the header and a few rows that have a byte above 127, and add it with layer.addData and the same parameters. The file is refused with is not UTF-8 text.

Expected behavior

The file opens. When the bytes aren't valid UTF-8, the text is read as Windows-1252 (a superset of Latin-1 for printable text), and a notice says so, as the "Never silent" rule asks, for example "read as Windows-1252, since it isn't UTF-8". An encoding parameter on layer.addData/layer.addUrl could let a script say which encoding to use.

How are you running RustGIS?

Command line (rustgis-cli). Add Data in the desktop app uses the same reader.

Version

RustGIS 0.5.0 (release build), and main at the time of writing, whose CSV path is unchanged.

Operating system, browser and graphics

Windows 11.

Sample data

The CNES zip above, or any CSV saved as Latin-1 with an accented character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions