WordPress.org

Ready to get started?Download WordPress

Forums

Theme-Check
[resolved] A bug which identifies tags incorrectly in the stylesheet (3 posts)

  1. Jesin A
    Member
    Posted 10 months ago #

    Running this plugin on the theme I developed I got the following error

    WARNING: Found wrong tag, remove before { from your style.css header.

    But I did not have the Tags: field in styles.css at all so why didn't I get

    RECOMMENDED: Tags: is either empty or missing in style.css header.

    Finally I found that the following block of CSS code was causing the problem.

    .post-tags:before {
    /*Some styles here*/
    }

    After a bit of digging into the plugin's code I found the culprit on line 235 of checkbase.php

    if ( preg_match('|Tags:(.*)|i', $theme_data, $tags) )
    $tags = array_map( 'trim', explode( ',', wp_kses( trim( $tags[1] ), array() ) ) );
    else
    $tags = array();

    The first line matches the first string containing "Tags:" case insensitively which was why .post-tags: matched and before { detected as something NOT present in $allowed_tags list.

    Fixing it:

    Simple:
    Change |Tags:(.*)|i to |^Tags:(.*)|i so that only strings that start with "tags" are matched.

    Advanced:
    Match the string "Tags:" only if it is inside comments /* */

    |\/\*.*Tags:(.*)\n.*\*\/|isU

    Reproducing the error:

    Remove "Tags:" from the header of "style.css" and have something in your CSS code like

    .something-tags:pseudo {
    }

    Hope Simon Prosser and Samuel Wood will fix it in the next release.

    http://wordpress.org/plugins/theme-check/

  2. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 10 months ago #

    This is a bit of an edge case thing. You could simply add some valid tags to the top of the stylesheet and it would be eliminated.

    Note that theme-check is specifically meant for themes that are intended to be submitted to the WordPress.org repository, as a sort of "pre-flight" check system. Every theme submitted to the repository probably will have valid Tags in the header of the stylesheet.

    Also, requiring the Tags bit to be at the front of the line would not work, because many themes have spaces in their comments on the left side, for various stylistic reasons. It needs to catch those too. Your second suggestion might work, but only shoves the problem to cases where somebody has tags: in a comment later.

  3. Jesin A
    Member
    Posted 10 months ago #

    Hi Samuel you're right about the problem with the first regex but the second one seems foolproof to me.

    I checked it with the regex testing tool http://www.solmetra.com/scripts/regex/index.php with the following options

    Enter regular expression here:
    |\/\*.*Tags:(.*)\n.*\*\/|isU

    Enter your data here:

    /*
    Theme Name: Twenty Thirteen
    Theme URI: http://wordpress.org/themes/twentythirteen
    Author: the WordPress team
    Author URI: http://wordpress.org/
    Description: The 2013 theme for WordPress takes us back to the blog, featuring a full range of post formats, each displayed beautifully in their own unique way. Design details abound, starting with a vibrant color scheme and matching header images, beautiful typography and icons, and a flexible layout that looks great on any device, big or small.
    Version: 1.0
    License: GNU General Public License v2 or later
    */
    
    * {
    	-webkit-box-sizing: border-box;
    	-moz-box-sizing:    border-box;
    	box-sizing:         border-box;
    }
    
    article,
    aside,
    details,
    figcaption,
    figure,
    footer,
    header,
    nav,
    section,
    summary {
    	display: block;
    }
    
    audio,
    canvas,
    video {
    	display: inline-block;
    }
    
    audio:not([controls]) {
    	display: none;
    	height: 0;
    }
    
    [hidden] {
    	display: none;
    }
    
    html {
    	font-size: 100%;
    	overflow-y: scroll;
    	-webkit-text-size-adjust: 100%;
    	-ms-text-size-adjust: 100%;
    }
    
    /*
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
    Text Domain: twentythirteen
    
    This theme, like WordPress, is licensed under the GPL.
    Use it to make something cool, have fun, and share what you've learned with others.
    */

    Type: Perl
    Function: preg_match
    Flags: None

    As you said I separated the "Tags:" from the header comments block and put it below and looking at the [1] index of the Resultset: I see only the tag values.

    The reason I'm stressing on this is because it misleads new developers. If someone forgets to put "Tags:" in the header comments and has a class or id selector with the string "tags" followed by a pseudo class they would get a WARNING telling them about a "wrong tag" instead of missing "Tags:"

    When I got this error I thought that either somewhere the syntax of my CSS is wrong or this plugin has a problem with the :before pseudo class.

    If all this seems too much to do please include more details in the WARNING message for non-allowed tags like

    WARNING: Found wrong tag, remove %s from the Tags: field in your style.css header.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags