Case-fold the Windows username before sanitization

Bug #2122047 reported by Carlos Nihelton
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
wsl-setup (Ubuntu)
Status tracked in Resolute
Resolute
Fix Released
High
Unassigned

Bug Description

The `wsl-setup` script reads the Windows user name and sanitizes it,
dropping invalid characters for a Linux user name, including ASCII upper
case letters. We could case fold the username first and then drop the
invalid ones, making it a bit less surprising. That would still have
some nasty cases we cannot handle in a smart way, like `MartínJoão` being
converted into `martnjoo` but that’s why we prompt for the username, to
let users edit that before actual submission.

While case folding can be done with `tr "[:upper:]" "[:lower:]"` or even
better `awk '{print tolower(0)}'` (awk handles Unicode better), better yet
is to leverage PowerShell because then we're guaranteed to respect the
Windows user locale (a WSL instance could be set up with a different
locale and the case-folding results couldn't match the user's
expectation).

To illustrate how this works:

```bash
j@DESKTOP-551PQ9O:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal

j@DESKTOP-551PQ9O:~$ powershell.exe -Command '$Env:Username'
João

j@DESKTOP-551PQ9O:~$ var="Username"; powershell.exe -NoProfile -Command '& {
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$Env:'"${var}"'}'
João

j@DESKTOP-551PQ9O:~$ var="Username.ToLower()"; powershell.exe -NoProfile -Command '& {
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$Env:'"${var}"'}'
joão

```

In the example above the username would be sanitized to: `oo`
but with the changes it would at least be: `joo`
(the 'ã' is still dropped, but it's much easier to add it).

The motivation for this change came from a user named `AdminUser`.
That would originally be sanitized to: `dminser`
but now it becomes: `adminuser`

One must remember that in the end this name is just a suggestion
prefilling a read input. User is free to edit it before hitting enter
and submitting the username to the `adduser` program.

Related branches

description: updated
description: updated
Revision history for this message
Paride Legovini (paride) wrote :

Can you please attach a debdiff of the proposed change, or point to a MR against a git-ubuntu branch? Thanks!

Changed in wsl-setup (Ubuntu):
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for wsl-setup (Ubuntu) because there has been no activity for 60 days.]

Changed in wsl-setup (Ubuntu):
status: Incomplete → Expired
summary: - [FFe] Case-fold the Windows username before sanitization
+ Case-fold the Windows username before sanitization
description: updated
Changed in wsl-setup (Ubuntu):
status: Expired → New
Revision history for this message
Carlos Nihelton (cnihelton) wrote (last edit ):

A git-ubuntu branch is presented via the linked MP to address this bug by uploading the new upstream release to resolute. Sponsors can freely ignore that branch and just checkout the tag 0.6.1 from the upstream repository (github.com/ubuntu/wsl-setup), build the source package and upload it. The commit IDs would be different but the contents are the same.

Changed in wsl-setup (Ubuntu Resolute):
importance: Undecided → High
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package wsl-setup - 0.6.1

---------------
wsl-setup (0.6.1) resolute; urgency=medium

  [ Kat Kuo]
  * Added ubuntu-insights integration
  * Added integration tests in upstream CI

  [Carlos Nihelton]
  * Case-fold the Windows username before sanitization (LP: #2122047)
  * Remove the systemd-timesyncd.service override that would enable it in WSL

 -- Kat Kuo <email address hidden> Tue, 25 Nov 2025 19:56:56 -0500

Changed in wsl-setup (Ubuntu Resolute):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.