Skip to content

Commit 134ef96

Browse files
committed
Small regexp improvement + test on CI
1 parent 4c2dc79 commit 134ef96

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

.github/workflows/run-code-blocks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
- uses: actions/setup-python@v5
3131
with:
3232
python-version: '3.13'
33+
- name: Check script readiness
34+
run: python -m unittest scripts/md-k6.py
3335
- name: Run Updated Code Blocks
3436
env:
3537
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}

docs/sources/k6/next/javascript-api/jslib/http-instrumentation-pyroscope/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This module, by default, adds three key-value pairs:
3434

3535
## Example
3636

37-
This example demonstrates how to use the this library to instrument every HTTP request made in a script with the `baggage` header.
37+
This example demonstrates how to use the this library to instrument every HTTP request made in a script with the `baggage` header TEST.
3838

3939
{{< code >}}
4040

scripts/md-k6.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Usage:
55
# python3 md-k6.py <file>
66

7+
import io
78
import os
89
import re
910
import json
@@ -221,10 +222,11 @@ def read_front_matter_env(f: TextIO) -> dict[str, str]:
221222
continue
222223

223224
parts = line.strip().split(":")
224-
key, value = parts[0].strip(), parts[1].strip()
225+
key = parts[0].strip()
226+
value = ":".join(parts[1:]).strip()
225227

226228
# Look for YAML keys with ALL_CAPS_NAMES
227-
if re.match(r"[A-Z0-9_]", key) and value:
229+
if re.match(r"^[A-Z0-9_]+$", key) and value:
228230
result[key] = value
229231

230232
return result
@@ -344,6 +346,26 @@ def testExtractScriptIndexEnv(self):
344346
self.assertEqual(len(scripts), 1)
345347
self.assertEqual(scripts[0].text, "testing testing")
346348

349+
def testReadIndexEnvFile(self):
350+
text = io.StringIO(
351+
"""
352+
---
353+
title: Testing
354+
FOO_BAR: 1234
355+
FOO_BAR2:1234
356+
FOO_BAR3: some:value
357+
not_added: foo
358+
not_added2:
359+
NOT_ADDED3:
360+
---
361+
"""
362+
)
363+
env = read_front_matter_env(text)
364+
365+
self.assertEqual(
366+
env, {"FOO_BAR": "1234", "FOO_BAR2": "1234", "FOO_BAR3": "some:value"}
367+
)
368+
347369
def testExtractScriptOptions(self):
348370
text = """
349371
<!-- md-k6:nofail,env.A=B,env.C=X- -->

0 commit comments

Comments
 (0)