Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Escape user-supplied strings regex #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2025
Merged

Escape user-supplied strings regex #339

merged 3 commits into from
Jun 3, 2025

Conversation

ayjayt
Copy link
Collaborator

@ayjayt ayjayt commented Jun 2, 2025

fix bug related to plotly/plotly.js#7412 (comment)

@emilykl
Copy link
Collaborator

emilykl commented Jun 2, 2025

@ayjayt Commit 4967954 is still failing for me when following the steps here. Are you seeing the same thing? It looks like prefix and ext need to be escaped in the glob as well.

Here is the output I'm getting:

(make_baseline) (base) ekl@Emilys-MacBook-Air-2 failing_figures_kaleido_v1 % python generate_images.py 
=============
=== Failed to generate image for gl3d_streamtube_reversed_ranges ===
=============
Traceback (most recent call last):
  File "generate_images.py", line 32, in <module>
    pio.write_image(
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/plotly/io/_kaleido.py", line 509, in write_image
    img_data = to_image(
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/plotly/io/_kaleido.py", line 379, in to_image
    img_bytes = kaleido.calc_fig_sync(
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/__init__.py", line 145, in calc_fig_sync
    return _async_thread_run(calc_fig, args=args, kwargs=kwargs)
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/__init__.py", line 138, in _async_thread_run
    raise res
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/__init__.py", line 129, in run
    q.put(asyncio.run(func(*args, **kwargs)))
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/__init__.py", line 55, in calc_fig
    return await k.calc_fig(
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/kaleido.py", line 319, in calc_fig
    spec, full_path = build_fig_spec(fig, path, opts)
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/_fig_tools.py", line 146, in build_fig_spec
    name = _next_filename(directory, prefix, ext)
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/_fig_tools.py", line 97, in _next_filename
    numbers = [
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/_fig_tools.py", line 97, in <listcomp>
    numbers = [
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/pathlib.py", line 1139, in glob
    selector = _make_selector(tuple(pattern_parts), self._flavour)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/pathlib.py", line 473, in _make_selector
    return cls(pat, child_parts, flavour)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/pathlib.py", line 529, in __init__
    self.match = flavour.compile_pattern(pat)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/pathlib.py", line 315, in compile_pattern
    return re.compile(fnmatch.translate(pattern)).fullmatch
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 834, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 598, in _parse
    raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range _-2 at position 98
=============
=============
=== Failed to generate image for mathjax ===
=============
Traceback (most recent call last):
  File "generate_images.py", line 32, in <module>
    pio.write_image(
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/plotly/io/_kaleido.py", line 509, in write_image
    img_data = to_image(
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/plotly/io/_kaleido.py", line 379, in to_image
    img_bytes = kaleido.calc_fig_sync(
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/__init__.py", line 145, in calc_fig_sync
    return _async_thread_run(calc_fig, args=args, kwargs=kwargs)
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/__init__.py", line 138, in _async_thread_run
    raise res
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/__init__.py", line 129, in run
    q.put(asyncio.run(func(*args, **kwargs)))
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/__init__.py", line 55, in calc_fig
    return await k.calc_fig(
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/kaleido.py", line 319, in calc_fig
    spec, full_path = build_fig_spec(fig, path, opts)
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/_fig_tools.py", line 146, in build_fig_spec
    name = _next_filename(directory, prefix, ext)
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/_fig_tools.py", line 97, in _next_filename
    numbers = [
  File "/Users/ekl/code/plotly.js/venv/make_baseline/lib/python3.8/site-packages/kaleido/_fig_tools.py", line 97, in <listcomp>
    numbers = [
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/pathlib.py", line 1139, in glob
    selector = _make_selector(tuple(pattern_parts), self._flavour)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/pathlib.py", line 473, in _make_selector
    return cls(pat, child_parts, flavour)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/pathlib.py", line 529, in __init__
    self.match = flavour.compile_pattern(pat)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/pathlib.py", line 315, in compile_pattern
    return re.compile(fnmatch.translate(pattern)).fullmatch
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 834, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/Users/ekl/.local/share/uv/python/cpython-3.8.20-macos-aarch64-none/lib/python3.8/sre_parse.py", line 598, in _parse
    raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range {-\\ at position 47
=============

@ayjayt
Copy link
Collaborator Author

ayjayt commented Jun 2, 2025

hmm i don't get those errors let me take a look

@emilykl
Copy link
Collaborator

emilykl commented Jun 2, 2025

b83b6b8 is working for me 👍

@ayjayt ayjayt force-pushed the andrew/sanitize-regex branch from ae2d49a to b83b6b8 Compare June 3, 2025 16:27
@ayjayt ayjayt merged commit fd7da80 into master Jun 3, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants