Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/YOURLS/YOURLS.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author྅༻ Ǭɀħ ༄༆ཉ <ozh@ozh.org>2022-03-12 20:02:26 +0300
committerGitHub <noreply@github.com>2022-03-12 20:02:26 +0300
commitac4613a1f96f277efe35f50ebd9a95c5b46407c8 (patch)
tree4614c2a68e422df9c2b1339174513138ac221775
parent8fbe2b9ffe4596de76285415f06546d386e2e68e (diff)
Make element ID independent from the short URL (#3244)
Fixing a dumb idea introduced in version 0.1 :^P Fixes #2925
-rw-r--r--includes/functions-deprecated.php10
-rw-r--r--includes/functions-formatting.php11
-rw-r--r--includes/functions-html.php4
-rw-r--r--tests/tests/format/general.php25
4 files changed, 27 insertions, 23 deletions
diff --git a/includes/functions-deprecated.php b/includes/functions-deprecated.php
index daa2308a..9a0b3cc7 100644
--- a/includes/functions-deprecated.php
+++ b/includes/functions-deprecated.php
@@ -10,6 +10,16 @@
// @codeCoverageIgnoreStart
/**
+ * Return a unique(ish) hash for a string to be used as a valid HTML id
+ *
+ * @deprecated 1.8.3
+ */
+function yourls_string2htmlid( $string ) {
+ yourls_deprecated_function( __FUNCTION__, '1.8.3', 'yourls_unique_element_id' );
+ return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) );
+}
+
+/**
* Get search text from query string variables search_protocol, search_slashes and search
*
* Some servers don't like query strings containing "(ht|f)tp(s)://". A javascript bit
diff --git a/includes/functions-formatting.php b/includes/functions-formatting.php
index cb826b74..08ac8d93 100644
--- a/includes/functions-formatting.php
+++ b/includes/functions-formatting.php
@@ -43,11 +43,16 @@ function yourls_string2int( $string, $chars = null ) {
}
/**
- * Return a unique(ish) hash for a string to be used as a valid HTML id
+ * Return a unique string to be used as a valid HTML id
+ *
+ * @since 1.8.3
+ * @param string $prefix Optional prefix
+ * @return string The unique string
*
*/
-function yourls_string2htmlid( $string ) {
- return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) );
+function yourls_unique_element_id($prefix = 'yid') {
+ static $id_counter = 0;
+ return yourls_apply_filter( 'unique_element_id', $prefix . (string)++$id_counter );
}
/**
diff --git a/includes/functions-html.php b/includes/functions-html.php
index 46432f0c..4de8891f 100644
--- a/includes/functions-html.php
+++ b/includes/functions-html.php
@@ -488,7 +488,7 @@ function yourls_die( $message = '', $title = '', $header_code = 200 ) {
*/
function yourls_table_edit_row( $keyword ) {
$keyword = yourls_sanitize_keyword($keyword);
- $id = yourls_string2htmlid( $keyword ); // used as HTML #id
+ $id = yourls_unique_element_id();
$url = yourls_get_keyword_longurl( $keyword );
$title = htmlspecialchars( yourls_get_keyword_title( $keyword ) );
$safe_url = yourls_esc_attr( $url );
@@ -524,7 +524,7 @@ RETURN;
*/
function yourls_table_add_row( $keyword, $url, $title, $ip, $clicks, $timestamp ) {
$keyword = yourls_sanitize_keyword($keyword);
- $id = yourls_string2htmlid( $keyword ); // used as HTML #id
+ $id = yourls_unique_element_id();
$shorturl = yourls_link( $keyword );
$statlink = yourls_statlink( $keyword );
diff --git a/tests/tests/format/general.php b/tests/tests/format/general.php
index 158a9ddc..3dbf834d 100644
--- a/tests/tests/format/general.php
+++ b/tests/tests/format/general.php
@@ -99,26 +99,15 @@ class Format_General extends PHPUnit\Framework\TestCase {
}
/**
- * Some random keywords
- */
- public function some_random_keywords() {
- return array(
- array( '1' ),
- array( 'a' ),
- array( 'hello-world' ),
- array( '1337ozhOZH' ),
- array( '@#!?*' ),
- );
- }
-
- /**
- * Checking that string2htmlid is an alphanumeric string
+ * Checking that yourls_unique_element_id is a unique string
*
- * @dataProvider some_random_keywords
- * @since 0.1
*/
- public function test_string2htmlid( $string ) {
- $this->assertTrue( ctype_alnum( yourls_string2htmlid( $string ) ) );
+ public function test_string2htmlid() {
+ $id1 = yourls_unique_element_id();
+ $id2 = yourls_unique_element_id();
+ $this->assertIsString($id1);
+ $this->assertIsString($id2);
+ $this->assertNotSame($id1, $id2);
}
/**