<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/gal-ne-fixing-double-encoded-port-files-owm9xuunz" -->

---
title: GalÃ¨ne: fixing double-encoded port files | daily.dev
description: A FreshPorts bug since July 2024 double-encoded non-ASCII text in port Makefiles, pkg-messages and distinfo files, turning 'Galène' into 'GalÃ¨ne'. The code...
canonical: https://daily.dev/posts/gal-ne-fixing-double-encoded-port-files-owm9xuunz
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: GalÃ¨ne: fixing double-encoded port files | daily.dev
og:description: A FreshPorts bug since July 2024 double-encoded non-ASCII text in port Makefiles, pkg-messages and distinfo files, turning 'Galène' into 'GalÃ¨ne'. The code...
og:url: https://daily.dev/posts/gal-ne-fixing-double-encoded-port-files-owm9xuunz
og:image: https://api.daily.dev/og/posts/Owm9xuUnZ.png
og:image:alt: GalÃ¨ne: fixing double-encoded port files
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# GalÃ¨ne: fixing double-encoded port files

**[Planet PostgreSQL](https://daily.dev/sources/planet-postgresql)** · 10 min read · 1 upvotes · 0 comments

## Summary

A FreshPorts bug since July 2024 double-encoded non-ASCII text in port Makefiles, pkg-messages and distinfo files, turning 'Galène' into 'GalÃ¨ne'. The code read every file as Latin-1 instead of UTF-8 before storing it as UTF-8 again. The fix now reads files as raw bytes, decodes strict UTF-8, and falls back to Latin-1 only when needed, printing a warning in that case. Of 35 affected ports, only german/ding's Makefile isn't valid UTF-8. A separate SQL repair using PostgreSQL's convert_to/convert/convert_from functions will reverse the double encoding in already-stored data, covering 318 commit log descriptions, 67 long descriptions, and more.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://postgr.es/p/9Dd>

## Questions this post answers

### What causes double-encoded UTF-8 text like 'Ã¨' appearing instead of 'è' in a database?

Double encoding happens when UTF-8 bytes are read as Latin-1 (or another single-byte encoding) and then stored as UTF-8 again. Each original UTF-8 byte becomes its own Latin-1 character, which then gets re-encoded. For example, the two UTF-8 bytes for 'è' get misread as Latin-1 characters 'Ã' and '¨', which are then separately stored as valid UTF-8.

_daily.dev surfaces practical encoding postmortems like this one for developers debugging similar mojibake bugs._

### Can double-encoded UTF-8 text be reversed to recover the original characters?

Yes, double encoding can be reversed exactly since no information is lost. Converting the stored text from UTF-8 back to Latin-1 turns each character back into its original byte, recovering the original UTF-8 text. In PostgreSQL, this is done with convert_to(), convert(), and convert_from() against a SQL_ASCII-encoded column that stores raw bytes without validation.

_developers planning a similar data repair can track real-world PostgreSQL encoding fixes on daily.dev._

### How do you safely detect whether a text value is valid UTF-8 in PostgreSQL?

You can use a function that attempts to convert the raw bytes back to UTF-8 with convert_from(convert_to(t, 'SQL_ASCII'), 'UTF8') inside a PL/pgSQL block, catching the 'character_not_in_repertoire' exception to return true if the conversion fails, meaning the text is not valid UTF-8. This check runs before attempting any repair to avoid corrupting already-correct values.

_daily.dev helps developers building data-repair scripts keep up with encoding edge cases like this one._

## Similar posts on daily.dev

- [Ten ways a glibc change can break your PostgreSQL cluster](https://daily.dev/posts/ten-ways-a-glibc-change-can-break-your-postgresql-cluster-qwgewysx6) · Percona Blog · 1 upvotes · 1 comments
- [CVE-2026-46644: insecure equivalence in symfony/polyfill-intl-idn for ASCII-only xn-- labels \(Symfony Blog\)](https://daily.dev/posts/cve-2026-46644-insecure-equivalence-in-symfony-polyfill-intl-idn-for-ascii-only-xn---labels-symfon-snlmcskyi) · Symfony · 0 upvotes · 0 comments
- [FrankenPHP v1.11.2 Released With 30% Faster CGO, 40% Faster GC, and Security Patches](https://daily.dev/posts/frankenphp-v1-11-2-released-with-30-faster-cgo-40-faster-gc-and-security-patches-t7agr1poj) · Laravel News · 1 upvotes · 0 comments
- [PostGREShell: A Decadelong PostgreSQL Vulnerability Revealed](https://daily.dev/posts/postgreshell-a-decadelong-postgresql-vulnerability-revealed-ewywwcoxd) · Medium · 2 upvotes · 0 comments
- [GHSA-744p-w4gc-m3gh \(trilogy\): SQL injection through \`Trilogy\#escape\` with multibyte encodings](https://daily.dev/posts/ghsa-744p-w4gc-m3gh-trilogy-sql-injection-through-trilogy-escape-with-multibyte-encodings-o1nvhvcbw) · RUBYLAND · 0 upvotes · 0 comments

---

Tags: [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/gal-ne-fixing-double-encoded-port-files-owm9xuunz)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"GalÃ¨ne: fixing double-encoded port files","url":"https://daily.dev/posts/gal-ne-fixing-double-encoded-port-files-owm9xuunz","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/gal-ne-fixing-double-encoded-port-files-owm9xuunz"},"datePublished":"2026-11-22T01:46:12.640Z","dateModified":"2026-11-22T01:46:45.079Z","description":"A FreshPorts bug since July 2024 double-encoded non-ASCII text in port Makefiles, pkg-messages and distinfo files, turning 'Galène' into 'GalÃ¨ne'. The code...","image":"https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001","thumbnailUrl":"https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001","isAccessibleForFree":true,"articleSection":"Planet PostgreSQL","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Planet PostgreSQL","logo":"https://media.daily.dev/image/upload/logos/placeholder.jpg","url":"https://daily.dev/sources/planet-postgresql"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/gal-ne-fixing-double-encoded-port-files-owm9xuunz","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"postgresql","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Planet PostgreSQL","item":"https://daily.dev/sources/planet-postgresql"},{"@type":"ListItem","position":3,"name":"GalÃ¨ne: fixing double-encoded port files"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/gal-ne-fixing-double-encoded-port-files-owm9xuunz#faq","mainEntity":[{"@type":"Question","name":"What causes double-encoded UTF-8 text like 'Ã¨' appearing instead of 'è' in a database?","acceptedAnswer":{"@type":"Answer","text":"Double encoding happens when UTF-8 bytes are read as Latin-1 (or another single-byte encoding) and then stored as UTF-8 again. Each original UTF-8 byte becomes its own Latin-1 character, which then gets re-encoded. For example, the two UTF-8 bytes for 'è' get misread as Latin-1 characters 'Ã' and '¨', which are then separately stored as valid UTF-8. daily.dev surfaces practical encoding postmortems like this one for developers debugging similar mojibake bugs."}},{"@type":"Question","name":"Can double-encoded UTF-8 text be reversed to recover the original characters?","acceptedAnswer":{"@type":"Answer","text":"Yes, double encoding can be reversed exactly since no information is lost. Converting the stored text from UTF-8 back to Latin-1 turns each character back into its original byte, recovering the original UTF-8 text. In PostgreSQL, this is done with convert_to(), convert(), and convert_from() against a SQL_ASCII-encoded column that stores raw bytes without validation. developers planning a similar data repair can track real-world PostgreSQL encoding fixes on daily.dev."}},{"@type":"Question","name":"How do you safely detect whether a text value is valid UTF-8 in PostgreSQL?","acceptedAnswer":{"@type":"Answer","text":"You can use a function that attempts to convert the raw bytes back to UTF-8 with convert_from(convert_to(t, 'SQL_ASCII'), 'UTF8') inside a PL/pgSQL block, catching the 'character_not_in_repertoire' exception to return true if the conversion fails, meaning the text is not valid UTF-8. This check runs before attempting any repair to avoid corrupting already-correct values. daily.dev helps developers building data-repair scripts keep up with encoding edge cases like this one."}}]}
```

