mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.14k stars 338 forks source link

Enable multiline regexp mode for patterm matcher #861

Closed ihar-orca closed 2 years ago

ihar-orca commented 2 years ago

In the case of pattern comparison with the multiline string, an incorrect result may occur when the matched substring appears in the not first line.

Example:

#!/bin/bash

apache2_conf="/etc/httpd/conf/httpd.conf
/etc/apache2/httpd.conf"

if [[ "$apache2_conf" == */etc/apache2* ]]; then
  exit 0
else
  exit 1
fi

returns 1 because generated regexp ^.*/etc/apache2.*$ (interp/runner.go, func match()) is not multiline enabled. this patch adds the (?m) flag into all autogenerated regexps in this function.

ihar-orca commented 2 years ago

Sorry for multiple commits, it seems that it's not squashed on my side

mvdan commented 2 years ago

SGTM but please add a test :)

ihar-orca commented 2 years ago

@mvdan test added

mvdan commented 2 years ago

This branch cannot be rebased due to conflicts

Not sure how you ended up there. Can you try squashing and rebasing your commits?

mvdan commented 2 years ago

Ah, ignore me, I can squash-merge.