Page MenuHomePhabricator

D19544.id.diff
No OneTemporary

D19544.id.diff

diff --git a/src/applications/files/document/PhabricatorDocumentRef.php b/src/applications/files/document/PhabricatorDocumentRef.php
--- a/src/applications/files/document/PhabricatorDocumentRef.php
+++ b/src/applications/files/document/PhabricatorDocumentRef.php
@@ -119,11 +119,23 @@
}
$snippet = $this->getSnippet();
- if (!preg_match('/^\s*[{[]/', $snippet)) {
+
+ // If the file is longer than the snippet, we don't detect the content
+ // as JSON. We could use some kind of heuristic here if we wanted, but
+ // see PHI749 for a false positive.
+ if (strlen($snippet) < $this->getByteLength()) {
return false;
}
- return phutil_is_utf8($snippet);
+ // If the snippet is the whole file, just check if the snippet is valid
+ // JSON. Note that `phutil_json_decode()` only accepts arrays and objects
+ // as JSON, so this won't misfire on files with content like "3".
+ try {
+ phutil_json_decode($snippet);
+ return true;
+ } catch (Exception $ex) {
+ return false;
+ }
}
public function getSnippet() {

File Metadata

Mime Type
text/plain
Expires
Sun, May 12, 12:32 PM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6280898
Default Alt Text
D19544.id.diff (1 KB)

Event Timeline