metabase / metabase/metabase

Incorrect handling of "\b" string in custom expression editor

Open
#68,624 1 comment 0 reactions 0 assignees View on GitHub
.Frontend .Team/Graphy Priority:P2 Querying/Notebook/Custom Expression Type:Bug
Dominant language
Clojure
Stars
49.3k
Forks
6.8k
Avg merge
1d 13h
Merged PRs (30d)
653

Description

### Describe the bug

If a custom expression uses "\b" in a string, the generated SQL is incorrect:

Image

Image

So GUI questions using `\b` are not producing correct results because the SQL is wrong.

This is mainly a problem in `regexextract` because `\b` is the boundary regex, but it also happens if you use `\b` in other functions like `contains` for whatever reason.

Doesn't seem to happen to other similar strings like `\s` or `\d`.

**Started happening in v54**, which is also version when we released the new custom expression editor, which makes me think it's an editor-to-SQL translation problem rather than anything else.

### To Reproduce

1. Start a new question on the People table on a sample DB (I tried both H2 and Postgres)
2. Create a new custom column `regextract([Name], '\bHudson\b')`. This should return `Hudson` on the first record in the table, where the name is Hudson Borer.
3. See the SQL. The generated SQL will contain special characters instead of `\b

### Expected behavior

Generate correct SQL with `\b`

### Logs

_No response_

### Information about your Metabase installation

```JSON
any v54+, master #b6edd15
```

### Severity

P2?

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue in the custom expression editor using the People table and `regexextract([Name], '\bHudson\b')` on a sample database. Inspect the generated SQL and compare it with the expected `\b` sequence; done means the expression produces the correct SQL and returns `Hudson` without converting the escape sequence into special characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure, sql
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.