@@ -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 ;
0 commit comments