Skip to content

Commit 13f3ce5

Browse files
committed
Fix regressions
1 parent 97d1a10 commit 13f3ce5

4 files changed

Lines changed: 46 additions & 59 deletions

File tree

controller/author.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ protected function create()
405405
));
406406
$authors['author'] = array($this->user->data['username'] => $this->user->data['user_id']);
407407

408+
if ($contrib->contrib_name_clean === '')
409+
{
410+
$contrib->generate_permalink();
411+
}
412+
408413
$error = $contrib->validate($settings['categories'], $authors, $settings['custom']);
409414

410415
if (($form_key_error = $message->validate_form_key()) !== false)

controller/contribution/manage.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ public function manage($contrib_type, $contrib)
194194

195195
$this->contrib->post_data($this->message);
196196

197+
if (!$this->is_moderator)
198+
{
199+
$this->settings['permalink'] = $this->contrib->contrib_name_clean;
200+
}
201+
else if ($this->settings['permalink'] === '')
202+
{
203+
$this->settings['permalink'] = $this->contrib->get_generated_permalink();
204+
}
205+
197206
$authors = $this->contrib->get_authors_from_usernames(array(
198207
'active_coauthors' => $this->settings['coauthors']['active'],
199208
'nonactive_coauthors' => $this->settings['coauthors']['nonactive'],
@@ -475,11 +484,6 @@ protected function submit($authors, $old_settings)
475484

476485
if ($this->settings['permalink'] != $this->contrib->contrib_name_clean)
477486
{
478-
if ($this->settings['permalink'] == '')
479-
{
480-
$this->contrib->generate_permalink();
481-
$this->settings['permalink'] = $this->contrib->contrib_name_clean;
482-
}
483487
$this->contrib->change_permalink($this->settings['permalink']);
484488
}
485489
}

includes/objects/contribution.php

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,29 +1570,27 @@ public function validate($contrib_categories, $authors, $custom_fields, $old_per
15701570
$error[] = phpbb::$user->lang['EMPTY_CONTRIB_NAME'];
15711571
}
15721572

1573-
$metadata = $this->__get_array();
1574-
unset(
1575-
$metadata['contrib_desc'],
1576-
$metadata['contrib_desc_bitfield'],
1577-
$metadata['contrib_desc_uid'],
1578-
$metadata['contrib_desc_options']
1573+
$metadata = array(
1574+
$this->contrib_name,
1575+
$new_permalink !== null ? $new_permalink : $this->contrib_name_clean,
15791576
);
15801577
$metadata = array_merge($metadata, $custom_fields);
15811578

15821579
$demos = json_decode($this->contrib_demo, true);
15831580
if (is_array($demos))
15841581
{
1585-
// JSON encoding can otherwise hide emoji behind surrogate escapes.
1582+
// JSON encoding can otherwise hide unsupported characters behind
1583+
// surrogate escapes.
15861584
$metadata['contrib_demo'] = implode("\n", $demos);
15871585
}
15881586

1589-
$metadata_has_emoji = false;
1587+
$metadata_has_unsupported = false;
15901588

15911589
foreach ($metadata as $value)
15921590
{
1593-
if (is_string($value) && unicode::contains_unsupported($value))
1591+
if (is_string($value) && unicode::contains_unsupported($value, false))
15941592
{
1595-
$metadata_has_emoji = true;
1593+
$metadata_has_unsupported = true;
15961594
$error[] = phpbb::$user->lang['CONTRIB_EMOJI_NOT_ALLOWED'];
15971595
break;
15981596
}
@@ -1632,13 +1630,7 @@ public function validate($contrib_categories, $authors, $custom_fields, $old_per
16321630
$error = array_merge($error, $this->type->validate_contrib_fields($custom_fields));
16331631

16341632
$permalink = $new_permalink !== null ? $new_permalink : $this->contrib_name_clean;
1635-
if (!$metadata_has_emoji && $permalink === '')
1636-
{
1637-
// If they leave it blank automatically create it
1638-
$permalink = $this->find_available_permalink($this->contrib_name);
1639-
}
1640-
1641-
if (!$metadata_has_emoji && ($permalink_error = $this->validate_permalink($permalink, $old_permalink)) !== false)
1633+
if (!$metadata_has_unsupported && ($permalink_error = $this->validate_permalink($permalink, $old_permalink)) !== false)
16421634
{
16431635
$error[] = $permalink_error;
16441636
}
@@ -1688,11 +1680,6 @@ public function validate($contrib_categories, $authors, $custom_fields, $old_per
16881680
$author = key($authors['author']);
16891681
$missing_coauthors = array_merge($authors['missing']['active_coauthors'], $authors['missing']['nonactive_coauthors']);
16901682

1691-
if (!empty($authors['emoji']) && !$metadata_has_emoji)
1692-
{
1693-
$error[] = phpbb::$user->lang['CONTRIB_EMOJI_NOT_ALLOWED'];
1694-
}
1695-
16961683
if (!empty($missing_coauthors))
16971684
{
16981685
$error[] = phpbb::$user->lang('COULD_NOT_FIND_USERS', phpbb_generate_string_list($missing_coauthors, phpbb::$user));
@@ -1738,18 +1725,17 @@ public function validate($contrib_categories, $authors, $custom_fields, $old_per
17381725
*/
17391726
public function generate_permalink()
17401727
{
1741-
$this->contrib_name_clean = $this->find_available_permalink($this->contrib_name);
1728+
$this->contrib_name_clean = $this->get_generated_permalink();
17421729
}
17431730

17441731
/**
17451732
* Generate an available contribution permalink.
17461733
*
1747-
* @param string $value
17481734
* @return string
17491735
*/
1750-
protected function find_available_permalink($value)
1736+
public function get_generated_permalink()
17511737
{
1752-
$clean_name = $this->generate_permalink_slug($value);
1738+
$clean_name = $this->generate_permalink_slug($this->contrib_name);
17531739
$append = '';
17541740
$i = 2;
17551741
while ($this->permalink_exists($clean_name . $append))
@@ -1762,18 +1748,22 @@ protected function find_available_permalink($value)
17621748
}
17631749

17641750
/**
1765-
* Generate a contribution permalink containing Unicode letters, numbers,
1766-
* and underscores.
1751+
* Generate a contribution permalink containing Unicode letters, combining
1752+
* marks, numbers, and underscores.
17671753
*
17681754
* @param string $value
17691755
* @return string
17701756
*/
17711757
protected function generate_permalink_slug($value)
17721758
{
1773-
$permalink = preg_replace('/[^\p{L}\p{N}_]+/u', '_', url::generate_slug($value));
1774-
$permalink = preg_replace('/_+/', '_', $permalink);
1775-
1776-
return trim($permalink, '_');
1759+
// Variation selectors control the presentation of the preceding
1760+
// character. They are combining marks, but have no place in a
1761+
// permalink and can otherwise survive after an emoji is removed.
1762+
$value = preg_replace('/[\x{FE00}-\x{FE0F}\x{E0100}-\x{E01EF}]/u', '', $value);
1763+
1764+
// Preserve repeated and surrounding underscores for compatibility with
1765+
// existing permalink rules.
1766+
return preg_replace('/[^\p{L}\p{M}\p{N}_]+/u', '_', url::generate_slug($value));
17771767
}
17781768

17791769
/*
@@ -1841,29 +1831,13 @@ public function permalink_exists($permalink)
18411831
*/
18421832
public function get_authors_from_usernames($authors)
18431833
{
1844-
$result = array(
1845-
'missing' => array(),
1846-
'emoji' => false,
1847-
);
1834+
$result = array('missing' => array());
18481835

18491836
foreach ($authors as $group => $users)
18501837
{
1851-
$valid_users = array();
1852-
1853-
foreach (explode("\n", $users) as $username)
1854-
{
1855-
if (unicode::contains_unsupported($username))
1856-
{
1857-
$result['emoji'] = true;
1858-
continue;
1859-
}
1860-
1861-
$valid_users[] = $username;
1862-
}
1863-
1864-
$user_data = user_helper::get_user_ids_from_list($this->db, implode("\n", $valid_users));
1865-
$result[$group] = $user_data['ids'];
1866-
$result['missing'][$group] = $user_data['missing'];
1838+
$users = user_helper::get_user_ids_from_list($this->db, $users);
1839+
$result[$group] = $users['ids'];
1840+
$result['missing'][$group] = $users['missing'];
18671841
}
18681842

18691843
return $result;

unicode.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ function ($matches)
5151
* phpBB's MySQL utf8 schema.
5252
*
5353
* @param string $value
54+
* @param bool $decode_ncr Whether to decode numeric character references.
5455
* @return bool
5556
*/
56-
public static function contains_unsupported($value)
57+
public static function contains_unsupported($value, $decode_ncr = true)
5758
{
58-
$value = utf8_decode_ncr($value);
59+
if ($decode_ncr)
60+
{
61+
$value = utf8_decode_ncr($value);
62+
}
5963

6064
return (bool) preg_match('/[\x{10000}-\x{10FFFF}]/u', $value);
6165
}

0 commit comments

Comments
 (0)