re2: allow and test RE2(NULL)

RE2(NULL) has always worked. Make sure it keeps working.

Change-Id: I999c69d04e71fa31a2f40cd834c47b328039ed3d
Reviewed-on: https://code-review.googlesource.com/c/re2/+/63631
Reviewed-by: Alan Donovan <adonovan@google.com>
diff --git a/re2/re2.cc b/re2/re2.cc
index ffdb367..2e00d22 100644
--- a/re2/re2.cc
+++ b/re2/re2.cc
@@ -143,6 +143,11 @@
 
 
 RE2::RE2(const char* pattern) {
+  // If absl::string_view becomes an alias for std::string_view,
+  // it will stop allowing NULL to be converted.
+  // Handle NULL explicitly to keep callers working no matter what.
+  if (pattern == NULL)
+    pattern = "";
   Init(pattern, DefaultOptions);
 }
 
diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc
index 04c040e..5c1822d 100644
--- a/re2/testing/re2_test.cc
+++ b/re2/testing/re2_test.cc
@@ -1688,4 +1688,12 @@
   ASSERT_EQ(s, "\x61\x63");
 }
 
+TEST(RE2, InitNULL) {
+  // RE2::RE2 accepts NULL. Make sure it keeps doing that.
+  RE2 re(NULL);
+  ASSERT_TRUE(re.ok());
+  ASSERT_TRUE(RE2::FullMatch("", re));
+  ASSERT_TRUE(RE2::FullMatch("", NULL));
+}
+
 }  // namespace re2