1
0
Fork 0
mirror of https://github.com/imjasonh/testscript-rs synced 2026-07-12 10:58:27 +00:00

Add explicit Unicode mode to regex patterns for proper Unicode handling (#40)

This commit is contained in:
Copilot 2025-10-12 15:36:56 +00:00 committed by GitHub
parent 2dfdbc818d
commit d059265fa1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 40 additions and 4 deletions

View file

@ -218,7 +218,14 @@ impl TestEnvironment {
/// Search for a pattern in files (like grep)
pub fn grep_files(&mut self, pattern: &str, files: &[String]) -> Result<()> {
let regex = Regex::new(pattern)
// Enable Unicode mode for proper Unicode character matching in grep patterns
let pattern_with_flags = if pattern.starts_with("(?") {
// Pattern already has flags, don't add more
pattern.to_string()
} else {
format!("(?u){}", pattern)
};
let regex = Regex::new(&pattern_with_flags)
.map_err(|e| Error::command_error("grep", format!("Invalid regex: {}", e)))?;
let mut _found_matches = false;

View file

@ -236,7 +236,9 @@ impl TestEnvironment {
|| expected_substituted.contains('*')
|| expected_substituted.contains('.')
{
let regex_pattern = format!("(?s){}", expected_substituted); // (?s) enables DOTALL mode
// Enable DOTALL mode (?s) for . to match newlines
// Enable Unicode mode (?u) for proper Unicode character matching
let regex_pattern = format!("(?su){}", expected_substituted);
let regex = Regex::new(&regex_pattern)
.map_err(|e| Error::command_error(output_type, format!("Invalid regex: {}", e)))?;