threads / patch / 46814

patchuserdiff: fix HTML hunk header regexp

Subject: [PATCH] userdiff: fix HTML hunk header regexp

## tl;dr

2 messages between Sep 23, 2017 and Sep 24, 2017. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Ilya Kantor· Sep 23, 2017, 07:53 UTC · lore
Current HTML header regexp doesn't match headers without attributes.

So it fails to match <h1>...</h1>, while <h1 class="smth">...</h1> matches. The fix makes attributes optional. The regexp is still far from perfect, but now it at least handles the common case.

Signed-off-by: Ilya Kantor <iliakan@gmail.com>
---
 userdiff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to userdiff.c +1 −2
diff --git a/userdiff.c b/userdiff.c
index 6321103ce..dbfb4e13c 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -38,7 +38,7 @@ IPATTERN("fortran",
  "|//|\\*\\*|::|[/<>=]="),
 IPATTERN("fountain", "^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
  "[^ \t-]+"),
-PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
+PATTERNS("html", "^[ \t]*(<[Hh][1-6]([ \t].*)?>.*)$",
  "[^<>= \t]+"),
 PATTERNS("java",
  "!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
--
2.14.1

---
Best Regards,
Ilya Kantor
Junio C Hamano· Sep 24, 2017, 01:15 UTC · re: Ilya Kantor · lore

Re: [PATCH] userdiff: fix HTML hunk header regexp

Ilya Kantor <iliakan@gmail.com> writes:
Show 23 quoted lines
> Current HTML header regexp doesn't match headers without attributes.
>
> So it fails to match <h1>...</h1>, while <h1 class="smth">...</h1> matches.
> The fix makes attributes optional.
> The regexp is still far from perfect, but now it at least handles the
> common case.
>
> Signed-off-by: Ilya Kantor <iliakan@gmail.com>
> ---
>  userdiff.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/userdiff.c b/userdiff.c
> index 6321103ce..dbfb4e13c 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -38,7 +38,7 @@ IPATTERN("fortran",
>   "|//|\\*\\*|::|[/<>=]="),
>  IPATTERN("fountain", "^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
>   "[^ \t-]+"),
> -PATTERNS("html", "^[ \t]*(<[Hh][1-6][ \t].*>.*)$",
> +PATTERNS("html", "^[ \t]*(<[Hh][1-6]([ \t].*)?>.*)$",
>   "[^<>= \t]+"),

What you sent seems to be whitespace damaged, but it was small enough for me to tweak it to apply ;-)

Will queue.  Thanks.

← back to recent threads