Skip to content

Commit aeff101

Browse files
Add comprehensive test scripts for double slash debugging
- debug_url_construction.py: Tests complete URL construction flow - test_comprehensive_double_slash.py: Tests 16 edge cases including multiple slashes - test_double_slash_fix.py: Validates the .replace() fix approach - All tests pass showing no double slashes in generated URLs Co-Authored-By: ahmad@reflex.dev <pourhakimi@pm.me>
1 parent 77f5f7b commit aeff101

File tree

3 files changed

+229
-0
lines changed

3 files changed

+229
-0
lines changed

debug_url_construction.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Debug script to understand the complete URL construction flow and identify
4+
where the double slash is coming from in the GitHub edit page URLs.
5+
"""
6+
7+
import sys
8+
sys.path.append('.')
9+
10+
def debug_url_construction():
11+
"""Debug the complete URL construction flow."""
12+
try:
13+
from pcweb.templates.docpage.docpage import convert_url_path_to_github_path
14+
15+
test_cases = [
16+
"/docs/getting-started/introduction/",
17+
"/docs/getting-started/introduction",
18+
"docs/getting-started/introduction/",
19+
"docs/getting-started/introduction",
20+
"/docs/vars/var-operations/",
21+
"/docs/api-reference/cli/",
22+
"//docs/getting-started/introduction/", # Edge case: double leading slash
23+
"/docs//getting-started/introduction/", # Edge case: double slash in middle
24+
]
25+
26+
print("Debugging URL construction flow:")
27+
print("=" * 80)
28+
29+
for test_path in test_cases:
30+
print(f"\nTesting path: '{test_path}'")
31+
32+
stripped_path = test_path.rstrip("/")
33+
print(f"After rstrip('/'): '{stripped_path}'")
34+
35+
github_path = convert_url_path_to_github_path(stripped_path)
36+
print(f"GitHub path: '{github_path}'")
37+
38+
full_url_before = f"https://github.com/reflex-dev/reflex-web/blob/main/{github_path}"
39+
print(f"Full URL before replace: '{full_url_before}'")
40+
41+
full_url_after = full_url_before.replace("main//", "main/")
42+
print(f"Full URL after replace: '{full_url_after}'")
43+
44+
has_double_slash_before = "main//" in full_url_before
45+
has_double_slash_after = "//" in full_url_after.replace("https://", "")
46+
fix_was_applied = full_url_before != full_url_after
47+
48+
print(f"Had double slash before fix: {has_double_slash_before}")
49+
print(f"Fix was applied: {fix_was_applied}")
50+
print(f"Still has double slash after fix: {has_double_slash_after}")
51+
52+
if has_double_slash_after:
53+
print("❌ ERROR: Double slash still present after fix!")
54+
elif has_double_slash_before and fix_was_applied:
55+
print("✅ SUCCESS: Double slash was fixed")
56+
elif not has_double_slash_before:
57+
print("✅ OK: No double slash to begin with")
58+
else:
59+
print("⚠️ WARNING: Unexpected state")
60+
61+
print("-" * 60)
62+
63+
except Exception as e:
64+
print(f"❌ Error in debug script: {e}")
65+
import traceback
66+
traceback.print_exc()
67+
68+
if __name__ == "__main__":
69+
debug_url_construction()

test_comprehensive_double_slash.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Comprehensive test script to verify the double slash fix works correctly
4+
for all possible edge cases and path formats.
5+
"""
6+
7+
import sys
8+
sys.path.append('.')
9+
10+
def test_comprehensive_double_slash_fix():
11+
"""Test that the double slash fix works for all edge cases."""
12+
try:
13+
from pcweb.templates.docpage.docpage import convert_url_path_to_github_path
14+
15+
test_cases = [
16+
("/docs/getting-started/introduction/", "docs/getting_started/introduction.md"),
17+
("/docs/vars/var-operations/", "docs/vars/var_operations.md"),
18+
("/docs/api-reference/cli/", "docs/api_reference/cli.md"),
19+
("/docs/library/forms/button/", "docs/library/forms/button.md"),
20+
21+
("docs/getting-started/introduction/", "docs/getting_started/introduction.md"),
22+
("docs/vars/var-operations/", "docs/vars/var_operations.md"),
23+
24+
("/docs/getting-started/introduction", "docs/getting_started/introduction.md"),
25+
("docs/getting-started/introduction", "docs/getting_started/introduction.md"),
26+
27+
("//docs/getting-started/introduction/", "docs/getting_started/introduction.md"),
28+
("/docs//getting-started/introduction/", "docs/getting_started/introduction.md"),
29+
("/docs/getting-started//introduction/", "docs/getting_started/introduction.md"),
30+
("docs//getting-started/introduction/", "docs/getting_started/introduction.md"),
31+
32+
("///docs/getting-started/introduction///", "docs/getting_started/introduction.md"),
33+
("docs///getting-started///introduction", "docs/getting_started/introduction.md"),
34+
35+
("/docs/getting-started/introduction.md", "docs/getting_started/introduction.md"),
36+
("docs/getting-started/introduction.md", "docs/getting_started/introduction.md"),
37+
]
38+
39+
print("Testing comprehensive double slash fix:")
40+
print("=" * 80)
41+
42+
all_passed = True
43+
44+
for i, (input_path, expected_output) in enumerate(test_cases, 1):
45+
print(f"\nTest {i:2d}: '{input_path}'")
46+
47+
actual_output = convert_url_path_to_github_path(input_path)
48+
print(f"Expected: '{expected_output}'")
49+
print(f"Actual: '{actual_output}'")
50+
51+
full_url = f"https://github.com/reflex-dev/reflex-web/blob/main/{actual_output}"
52+
print(f"Full URL: '{full_url}'")
53+
54+
has_double_slash = "//" in full_url.replace("https://", "")
55+
matches_expected = actual_output == expected_output
56+
57+
if matches_expected and not has_double_slash:
58+
print("✅ PASS")
59+
else:
60+
print("❌ FAIL")
61+
if not matches_expected:
62+
print(f" Expected '{expected_output}' but got '{actual_output}'")
63+
if has_double_slash:
64+
print(f" URL contains double slash: '{full_url}'")
65+
all_passed = False
66+
67+
print("-" * 60)
68+
69+
print("\n" + "=" * 80)
70+
if all_passed:
71+
print("🎉 SUCCESS: All tests passed! Double slash fix is working correctly.")
72+
else:
73+
print("❌ FAILURE: Some tests failed. Double slash issue not fully resolved.")
74+
75+
return all_passed
76+
77+
except Exception as e:
78+
print(f"❌ Error in comprehensive test: {e}")
79+
import traceback
80+
traceback.print_exc()
81+
return False
82+
83+
if __name__ == "__main__":
84+
success = test_comprehensive_double_slash_fix()
85+
exit(0 if success else 1)

test_double_slash_fix.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Test script to verify the double slash fix in GitHub edit page URLs.
4+
This script tests the convert_url_path_to_github_path function and URL construction
5+
to ensure no double slashes are generated.
6+
"""
7+
8+
import sys
9+
sys.path.append('.')
10+
11+
def test_double_slash_fix():
12+
"""Test that the double slash fix works correctly."""
13+
try:
14+
from pcweb.templates.docpage.docpage import convert_url_path_to_github_path
15+
16+
test_paths = [
17+
"/docs/getting-started/introduction/",
18+
"/docs/vars/var-operations/",
19+
"/docs/api-reference/cli/",
20+
"/docs/library/forms/button/",
21+
"docs/getting-started/introduction/", # without leading slash
22+
"/docs/getting-started/introduction", # without trailing slash
23+
]
24+
25+
print("Testing double slash fix in GitHub edit page URLs:")
26+
print("=" * 70)
27+
28+
all_good = True
29+
30+
for test_path in test_paths:
31+
github_path = convert_url_path_to_github_path(test_path)
32+
33+
full_url = f"https://github.com/reflex-dev/reflex-web/blob/main/{github_path}"
34+
35+
fixed_url = full_url.replace("main//", "main/")
36+
37+
has_double_slash = "main//" in full_url
38+
fix_applied = full_url != fixed_url
39+
40+
print(f"Input path: {test_path}")
41+
print(f"GitHub path: {github_path}")
42+
print(f"Full URL: {full_url}")
43+
print(f"Fixed URL: {fixed_url}")
44+
print(f"Had double //: {has_double_slash}")
45+
print(f"Fix applied: {fix_applied}")
46+
47+
if has_double_slash:
48+
print(f"⚠️ DOUBLE SLASH DETECTED (but fixed by .replace())")
49+
else:
50+
print(f"✅ No double slash")
51+
52+
print()
53+
54+
if "//" in fixed_url.replace("https://", ""):
55+
print(f"❌ ERROR: Final URL still contains double slashes!")
56+
all_good = False
57+
58+
print("=" * 70)
59+
if all_good:
60+
print("🎉 SUCCESS: Double slash fix is working correctly!")
61+
print("All URLs are properly formatted without double slashes.")
62+
else:
63+
print("❌ FAILURE: Some URLs still contain double slashes!")
64+
65+
return all_good
66+
67+
except Exception as e:
68+
print(f"❌ Error testing double slash fix: {e}")
69+
import traceback
70+
traceback.print_exc()
71+
return False
72+
73+
if __name__ == "__main__":
74+
success = test_double_slash_fix()
75+
exit(0 if success else 1)

0 commit comments

Comments
 (0)