qri-io / qri

you're invited to a data party!
https://qri.io
GNU General Public License v3.0
1.11k stars 66 forks source link

Starlark ”Invalid escape sequence \[” #1314

Closed feep closed 4 years ago

feep commented 4 years ago

Looks like it last worked in 0.9.6.

❯ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G3020

❯ cat minimal.star
load("re.star", "re")

def transform(ds, ctx):
    jsonblobhits = """
[hi]
[dustmop]
"""
    jsonblob = re.findall("\[.*]", jsonblobhits)
    error(jsonblob)

❯ qri version
0.9.8

❯ qri save --dry-run -f ./minimal.star me/humba
🏃🏽‍♀️ dry run
transform.star:9:27: invalid escape sequence \[

❯ 7qri version
0.9.7

❯ 7qri save --dry-run -f ./minimal.star me/humba
🏃🏽‍♀️ dry run
transform.star:9:27: invalid escape sequence \[

❯ 6qri version
0.9.6

❯ 6qri save --dry-run -f ./minimal.star me/humba
🏃🏽‍♀️ dry run
Traceback (most recent call last):
  transform.star:10:10: in transform
  <builtin>: in error
Error: transform error: ("[hi]", "[dustmop]")

The 0.9.6 result is correct. The test case calls error() to display the result.

dustmop commented 4 years ago

This could be related to this commit: https://github.com/qri-io/starlib/commit/2beea78d035874774a464b0ff6568bb159c00b14 which upgraded the version of starlark that we build off of. @b5 is this expected behavior for how starlark's regex's work? @feep did you try changing ("\[.*]", jsonblobhits) to (r"\[.*]", jsonblobhits)? Adding an "r" will make this a "raw string", which uses different rules for parsing escape sequences, and is often used for regex literals.

feep commented 4 years ago

@feep did you try changing ("[.]", jsonblobhits) to (r"[.]", jsonblobhits)?

In this test case, r"" works in all versions.

Also works in my code.

Using raw string seems to fix if you want to close.

Thanks.