@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix regression in PHUIObjectItemView.php:662: allow PhutilURI and other stringlike

Summary:
This fixes this specific exception that can happen with whatever PHP version in some pages:

Call to phutil_nonempty_string() expected null or a string, got: PhutilURI from PHUIObjectItemView.php:662

The regression was introduced since:

b56d86e48d0f63028cb5739c179d61ece2a24bb1

The problem is caused by the fact that we are trying to introduce very strict checks, and sometime we are too much strict.

In this specific case we use `phutil_nonempty_stringlike()` since it also allows objects with a `__toString()` method.

In order not to leave these cases to chance, we have added a log line, which can be removed in the future.

If you see this log line, report it in the respective Task. Thank you!

Closes T15306
Ref T15316

Test Plan:
1. {nav Dashboard > Add a Panel}: no crash
2. {nav Diffusion repo > README}: no crash
3. {nav Herald > Create}: no crash

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: avivey, aklapper, speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15306, T15316

Differential Revision: https://we.phorge.it/D25157

+58 -2
+58 -2
src/view/phui/PHUIObjectItemView.php
··· 83 83 return $this->object; 84 84 } 85 85 86 + /** 87 + * Set the href attribute 88 + * 89 + * @param string|PhutilURI|null $href 90 + * @return self 91 + */ 86 92 public function setHref($href) { 93 + 94 + // We have not a very clear idea about what this method should receive 95 + // So, let's log alien stuff for some time 96 + // https://we.phorge.it/T15316 97 + self::requireValidHref($href, 'href'); 98 + 87 99 $this->href = $href; 88 100 return $this; 89 101 } 90 102 103 + /** 104 + * Get the href attribute 105 + * 106 + * @see PHUIObjectItemView::setHref() 107 + * @return string|PhutilURI|null 108 + */ 91 109 public function getHref() { 92 110 return $this->href; 93 111 } ··· 136 154 return $this; 137 155 } 138 156 157 + /** 158 + * Set the image href attribute 159 + * 160 + * @param string|PhutilURI|null $image_href 161 + * @return self 162 + */ 139 163 public function setImageHref($image_href) { 164 + 165 + // We have not a very clear idea about what this method should receive 166 + // So, let's log alien stuff for some time 167 + // https://we.phorge.it/T15316 168 + self::requireValidHref($image_href, 'image_href'); 169 + 140 170 $this->imageHref = $image_href; 141 171 return $this; 142 172 } ··· 659 689 $this->getImageIcon()); 660 690 } 661 691 662 - if ($image && (phutil_nonempty_string($this->href) || 663 - phutil_nonempty_string($this->imageHref))) { 692 + if ($image && (phutil_nonempty_stringlike($this->href) || 693 + phutil_nonempty_stringlike($this->imageHref))) { 664 694 $image_href = ($this->imageHref) ? $this->imageHref : $this->href; 665 695 $image = phutil_tag( 666 696 'a', ··· 897 927 } 898 928 899 929 return javelin_tag('span', $options, ''); 930 + } 931 + 932 + 933 + /** 934 + * Receive a href attribute and check if it has expected values 935 + * 936 + * TODO: Feel free to remove after 2023, if no more new reports arrive. 937 + * 938 + * https://we.phorge.it/T15316 939 + * 940 + * @param mixed $href Value to be checked 941 + * @param string $variable_name Human reference 942 + */ 943 + private static function requireValidHref($href, $variable_name) { 944 + 945 + // We have not a very clear idea about what a "href" should be 946 + if (is_object($href) && !($href instanceof PhutilURI)) { 947 + 948 + // We log stuff with a kind stack trace 949 + phlog(new Exception(pht( 950 + 'The variable %s received an unexpected type: %s. '. 951 + 'Please share this stack trace as comment in Task %s', 952 + $variable_name, 953 + get_class($href), 954 + 'https://we.phorge.it/T15316'))); 955 + } 900 956 } 901 957 902 958 }