Making WordPress.org

Changeset 10573


Ignore:
Timestamp:
01/13/2021 01:24:14 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: When generating FAQ anchors, don't include trailing whitespace as part of the ID.

This also updates the format of pre-defined ID's to match the format used today, as the ID's were previously being stripped out by kses, there's no real change here.

The Decode/Encode and trimming works around the various different anchor formats used.

Fixes #5572.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php

    r10566 r10573  
    428428                $this->sections['faq'] .= "\n<dl>\n";
    429429                foreach ( $this->faq as $question => $answer ) {
    430                     $question_slug          = sanitize_title_with_dashes( $question );
     430                    $question_slug          = rawurlencode( trim( strtolower( $question ) ) );
    431431                    $this->sections['faq'] .= "<dt id='{$question_slug}'><h3>{$question}</h3></dt>\n<dd>{$answer}</dd>\n";
    432432                }
     
    524524            'ol'         => array(),
    525525            'dl'         => array(),
    526             'dt'         => array(),
     526            'dt'         => array(
     527                'id' => true,
     528            ),
    527529            'dd'         => array(),
    528530            'li'         => array(),
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/js/section-faq.js

    r9005 r10573  
    1111            // If there is no ID, create our own.
    1212            if ( ! id ) {
    13                 id = '#' + encodeURIComponent( $question.text().toLowerCase() );
     13                id = '#' + encodeURIComponent( $question.text().toLowerCase().trim() );
    1414                $question.attr( 'id', id );
    1515            }
     
    4343
    4444    if ( window.location.hash ) {
    45         questions.find( '[formaction="' + window.location.hash + '"]' ).trigger( 'click' );
     45        jQuery(
     46            // Decode/Encode here is to work with any existing links that are not fully-encoded, the trim handles whitespace/newlines.
     47            document.getElementById( encodeURIComponent( decodeURIComponent( window.location.hash.substr(1) ).trim() ) )
     48        ).trigger( 'click' );
    4649    }
    4750} )( jQuery );
Note: See TracChangeset for help on using the changeset viewer.