WordPress.org

Ready to get started?Download WordPress

Forums

Fix Double Slash Error (2 posts)

  1. GeoffreyF67
    Member
    Posted 8 years ago #

    I'm not sure where to post this but some of my URLs have been broken on my wordpress blogs for a while. The reason they were broken is they had a // at the end of the url.

    I finally spent some time and figured out the cause and fix for this bug.

    In wp-includes/functions-formatting.php there is a function called "trailingslashit":

    function trailingslashit($string) {
    if ( '/' != substr($string, -1)) {
    $string .= '/';
    }
    return $string;
    }

    This code should look like this:

    function trailingslashit($string) {
    if ( '/' != substr($string, -1,1)) {
    $string .= '/';
    }
    return $string;
    }

    Previously it was checking the entire string rather than the last character.

    This is my first time posting here so hopefully this will come out formatted correctly :)

    G-Man

  2. Firas
    Member
    Posted 8 years ago #

    The two substr() calls are equivalent… if you start 1 character from the right you have only one character left to go.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags