Invalid escape sequences in regexes when installing gedit

Bug #2061211 reported by Erik Roland van der Meer
74
This bug affects 10 people
Affects Status Importance Assigned to Milestone
gedit (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

On a clean install of the 24.04 beta, if you do a "sudo apt install gedit", you get the following messages at the end of the install:

/usr/lib/x86_64-linux-gnu/gedit/plugins/externaltools/library.py:212: SyntaxWarning: invalid escape sequence '\-'
  RE_KEY = re.compile('^([a-zA-Z_][a-zA-Z0-9_.\-]*)(\[([a-zA-Z_@]+)\])?$')
/usr/lib/x86_64-linux-gnu/gedit/plugins/snippets/substitutionparser.py:162: SyntaxWarning: invalid escape sequence '\s'
  match = re.match('\\\\?%s\s*' % self.REG_GROUP, tokens)

So there are 2 issues with regexes.

Bug #2055010 reports the first of these, but not the second, and it also reports a different issue as "the huger problem" (one that I can't reproduce). I hope I'm making the right call in opening a new bug report specifically for these regex issues.

Some more details:
- on the clean install, I did apply all available updates before trying to install gedit
- you can also reproduce this issue from the live ("try ubuntu") environment

ProblemType: Bug
DistroRelease: Ubuntu 24.04
Package: gedit 46.2-1build1
ProcVersionSignature: Ubuntu 6.8.0-22.22-generic 6.8.1
Uname: Linux 6.8.0-22-generic x86_64
NonfreeKernelModules: zfs
ApportVersion: 2.28.0-0ubuntu1
Architecture: amd64
CasperMD5CheckResult: pass
CasperVersion: 1.496
CloudArchitecture: x86_64
CloudID: nocloud
CloudName: unknown
CloudPlatform: nocloud
CloudSubPlatform: seed-dir (/var/lib/cloud/seed/nocloud)
CurrentDesktop: ubuntu:GNOME
Date: Sat Apr 13 08:41:26 2024
LiveMediaBuild: Ubuntu 24.04 LTS "Noble Numbat" - Beta amd64 (20240410.2)
ProcEnviron:
 LANG=C.UTF-8
 PATH=(custom, no user)
 SHELL=/bin/bash
 TERM=xterm-256color
 XDG_RUNTIME_DIR=<set>
SourcePackage: gedit
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Erik Roland van der Meer (ervdmeer) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gedit (Ubuntu):
status: New → Confirmed
Revision history for this message
fprietog (fprietog) wrote :

It can also be reproduced reinstalling gedit (in this example in aarch64 architecture):

# apt install --reinstall gedit
Leyendo lista de paquetes... Hecho
Creando árbol de dependencias... Hecho
Leyendo la información de estado... Hecho
0 actualizados, 0 nuevos se instalarán, 1 reinstalados, 0 para eliminar y 0 no actualizados.
Se necesita descargar 353 kB de archivos.
Se utilizarán 0 B de espacio de disco adicional después de esta operación.
Des:1 http://ports.ubuntu.com/ubuntu-ports noble/universe arm64 gedit arm64 46.2-2 [353 kB]
Descargados 353 kB en 0s (1.178 kB/s)
(Leyendo la base de datos ... 221724 ficheros o directorios instalados actualmente.)
Preparando para desempaquetar .../gedit_46.2-2_arm64.deb ...
Desempaquetando gedit (46.2-2) sobre (46.2-2) ...
Configurando gedit (46.2-2) ...
/usr/lib/aarch64-linux-gnu/gedit/plugins/externaltools/library.py:212: SyntaxWarning: invalid escape sequence '\-'
  RE_KEY = re.compile('^([a-zA-Z_][a-zA-Z0-9_.\-]*)(\[([a-zA-Z_@]+)\])?$')
/usr/lib/aarch64-linux-gnu/gedit/plugins/snippets/substitutionparser.py:162: SyntaxWarning: invalid escape sequence '\s'
  match = re.match('\\\\?%s\s*' % self.REG_GROUP, tokens)

Revision history for this message
michaelly (michaellaunay) wrote :

To get gedit working on Ubuntu 24.04.01 you must change string to raw :

```bash
michaellaunay@Caravale:~$ sudo dpkg-reconfigure gedit
​/usr/lib/x86_64-linux-gnu/gedit/plugins/externaltools/library.py:212: SyntaxWarning: invalid escape sequence '\-' and'\['
  RE_KEY = re.compile('^([a-zA-Z_][a-zA-Z0-9_.\-]*)(\[([a-zA-Z_@]+)\])?$')
​/usr/lib/x86_64-linux-gnu/gedit/plugins/snippets/substitutionparser.py:162: SyntaxWarning: invalid escape sequence '\s'
  match = re.match('\\?%s\s*' % self.REG_GROUP, tokens)
```

The "SyntaxWarning" warnings are due to invalid escape sequences in the strings within the Python scripts. These warnings appear when an escape sequence like '\-' or `\[` or `\s` is used without the string being marked as a raw string.

To fix these warnings, the affected strings need to be converted into raw strings by adding an `r` before the quotation marks. Here’s how to correct the two problematic lines in the mentioned Python files:

1. File `library.py`, line 212:

   Before the correction:

```Python
   RE_KEY = re.compile('^([a-zA-Z_][a-zA-Z0-9_.\-]*)(\[([a-zA-Z_@]+)\])?$')
```

   After the correction:
```Python
   RE_KEY = re.compile(r'^([a-zA-Z_][a-zA-Z0-9_.\-]*)(\[([a-zA-Z_@]+)\])?$')
```

2. File `substitutionparser.py`, line 162:

   Before the correction:
```Python
   match = re.match('\\?%s\s*' % self.REG_GROUP, tokens)
```

   After the correction:
```python
   match = re.match(r'\\?%s\s*' % self.REG_GROUP, tokens)
```

I manually edited these files to apply the corrections.

Revision history for this message
michaelly (michaellaunay) wrote :

Here’s how to reproduce
```bash
michaellaunay@Caravale:~$ sudo apt update && sudo apt dist-upgrade
michaellaunay@Caravale:~$ sudo apt install gedit
...
Paramétrage de gedit (46.2-2) ...
/usr/lib/x86_64-linux-gnu/gedit/plugins/externaltools/library.py:212: SyntaxWarning: invalid escape sequence '\-'
  RE_KEY = re.compile('^([a-zA-Z_][a-zA-Z0-9_.\-]*)(\[([a-zA-Z_@]+)\])?$')
/usr/lib/x86_64-linux-gnu/gedit/plugins/snippets/substitutionparser.py:162: SyntaxWarning: invalid escape sequence '\s'
  match = re.match('\\\\?%s\s*' % self.REG_GROUP, tokens)
```
Attached is the patch that applies the corrections described in my previous comment

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "This patch fixes invalid escape sequence warnings in library.py and substitutionparser.py by converting the affected strings to raw strings." seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Revision history for this message
fprietog (fprietog) wrote :

Same problem happen in Ubuntu 24.10 Oracular upgrade:

Configurando python3 (3.12.6-0ubuntu1) ...
running python rtupdate hooks for python3.12...
/usr/lib/x86_64-linux-gnu/gedit/plugins/externaltools/library.py:212: SyntaxWarning: invalid escape sequence '\-'
  RE_KEY = re.compile('^([a-zA-Z_][a-zA-Z0-9_.\-]*)(\[([a-zA-Z_@]+)\])?$')
/usr/lib/x86_64-linux-gnu/gedit/plugins/snippets/substitutionparser.py:162: SyntaxWarning: invalid escape sequence '\s'
  match = re.match('\\\\?%s\s*' % self.REG_GROUP, tokens)

tags: added: oracular
tags: added: plucky
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.