Further tweaks to safe and lang injection, a=chris

Chris Pollett [2019-06-09 02:Jun:th]
Further tweaks to safe and lang injection, a=chris
Filename
src/models/PhraseModel.php
diff --git a/src/models/PhraseModel.php b/src/models/PhraseModel.php
index 8394748c5..fe039efd9 100755
--- a/src/models/PhraseModel.php
+++ b/src/models/PhraseModel.php
@@ -730,6 +730,7 @@ class PhraseModel extends ParallelModel
         $materialized_match_conflict = false;
         $found_lang = false;
         $found_safe = false;
+        $found_media_image = false;
         foreach ($meta_words as $meta_word) {
             $pattern = "/(\s)($meta_word(\S)+)/";
             preg_match_all($pattern, $phrase, $matches);
@@ -752,6 +753,10 @@ class PhraseModel extends ParallelModel
                     $weight = substr($matches[2][0], strlen($meta_word));
                 }
             }
+            if (!empty($matches[0]) && substr($matches[0], 0, 11)
+                == 'media:image') {
+                $found_media_image = true;
+            }
             if ($meta_word == 'safe:' && !empty($matches[0])) {
                 $found_safe = true;
             }
@@ -767,7 +772,8 @@ class PhraseModel extends ParallelModel
             $phrase_string = "";
         }
         $found_metas = array_unique($found_metas);
-        if (!empty($found_metas) || !empty($phrase_string)) {
+        if (!$found_media_image &&
+            (!empty($found_metas) || !empty($phrase_string)) {
             if (!$found_lang) {
                 $lang_parts = explode("-", $locale_tag);
                 $found_metas[] = "lang:" . $lang_parts[0];
@@ -1548,7 +1554,8 @@ class PhraseModel extends ParallelModel
             $out_query = "";
             $pipe = "";
             foreach ($disjunct_phrases as $disjunct) {
-                if (!stristr($disjunct, "lang:")) {
+                if (!stristr($disjunct, "lang:")&&
+                    !stristr($disjunct, "media:image")) {
                     $locale_tag = L\guessLocaleFromString($original_query);
                     $lang_parts = explode("-", $locale_tag);
                     $disjunct .= " lang:" . $lang_parts[0];
ViewGit