Nguyễn Thái Ngọc Duy  <[email protected]> writes:

>  static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
>  {
> +     int icase, ascii_only;
>       int err;
>  
>       p->word_regexp = opt->word_regexp;
>       p->ignore_case = opt->ignore_case;
> +     icase          = opt->regflags & REG_ICASE || p->ignore_case;
> +     ascii_only     = !has_non_ascii(p->pattern);
>  
>       if (opt->fixed) {
>               p->fixed = 1;
> -     } else if (is_fixed(p->pattern, p->patternlen))
> +     } else if ((!icase || ascii_only) &&
> +                is_fixed(p->pattern, p->patternlen))
>               p->fixed = 1;

... we are not told to do "fixed" explicitly with "-F", and that is
safe for a literal pattern if the pattern is only ascii (with or
without -i) but not safe with "-i" when dealing with non-ascii
pattern.

Makes perfect sense.

>       else
>               p->fixed = 0;
> diff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-ascii.sh
> new file mode 100755
> index 0000000..b78a774
> --- /dev/null
> +++ b/t/t7812-grep-icase-non-ascii.sh
> @@ -0,0 +1,23 @@
> +#!/bin/sh
> +
> +test_description='grep icase on non-English locales'
> +
> +. ./lib-gettext.sh
> +
> +test_expect_success GETTEXT_LOCALE 'setup' '
> +     test_write_lines "TILRAUN: Halló Heimur!" >file &&
> +     git add file &&
> +     LC_ALL="$is_IS_locale" &&
> +     export LC_ALL
> +'
> +
> +test_have_prereq GETTEXT_LOCALE &&
> +test-regex "HALLÓ" "Halló" ICASE &&
> +test_set_prereq REGEX_LOCALE
> +
> +test_expect_success REGEX_LOCALE 'grep literal string, no -F' '
> +     git grep -i "TILRAUN: Halló Heimur!" &&
> +     git grep -i "TILRAUN: HALLÓ HEIMUR!"
> +'
> +
> +test_done
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to