Skip to content

Regex::match_() panic on non-matching input in debug builds #1848

@micaiah-effiong

Description

@micaiah-effiong

When using glib::Regex::match_() with an input string that does not match the pattern, the function panics in debug builds due to an incorrect assertion.

use glib::prelude::*;
use gtk::glib;

fn main() {
    let rx = glib::Regex::new(
        r"\d",
        glib::RegexCompileFlags::DEFAULT,
        glib::RegexMatchFlags::DEFAULT,
    )
    .unwrap()
    .unwrap();

    // This works (matches)
    let input = glib::GString::from("8");
    let _ = rx.match_(input.as_gstr(), glib::RegexMatchFlags::DEFAULT);
    println!("Matched '8' - OK");

    // This panics (no match)
    let input = glib::GString::from("a");
    let _ = rx.match_(input.as_gstr(), glib::RegexMatchFlags::DEFAULT);
    println!("Matched 'a' - OK"); // Never reached
}

Expected Behavior

match_() should return None when the input doesn't match the pattern.

Actual Behavior

Panic in debug builds:

panicked at /Users/me/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glib-0.21.3/src/regex.rs:180:13:
assertion `left == right` failed
  left: true
 right: false

Environment

glib-rs version: 0.21.3
OS: macOS

Am I using match_() incorrectly? I expected it to return None when there's no match rather than panic. Any help would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions