Making WordPress.org

Changeset 10429


Ignore:
Timestamp:
11/05/2020 03:37:13 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Readme Parser: Allow a File, URL, or now the raw readme contents to be passed to the Readme Parser.

This eases integration and re-use of the parser for other purposes.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme
Files:
2 edited

Legend:

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

    r10042 r10429  
    153153         * Parser constructor.
    154154         *
    155          * @param string $file_or_url
    156          */
    157         public function __construct( $file_or_url ) {
    158                 if ( $file_or_url ) {
    159                         $this->parse_readme( $file_or_url );
     155         * @param string $string A Filepath, URL, or contents of a readme to parse.
     156         */
     157        public function __construct( $string ) {
     158                if ( file_exists( $string ) || preg_match( '!^https?://!i', $string ) ) {
     159                        $this->parse_readme( $string );
     160                } elseif ( $string ) {
     161                        $this->parse_readme_contents( $string );
    160162                }
    161163        }
    … …  
    174176                $contents = file_get_contents( $file_or_url, false, $context );
    175177
     178                return $this->parse_readme_contents( $contents );
     179        }
     180
     181        /**
     182         * @param string $contents The contents of the readme to parse.
     183         * @return bool
     184         */
     185        protected function parse_readme_contents( $contents ) {
    176186                if ( preg_match( '!!u', $contents ) ) {
    177187                        $contents = preg_split( '!\R!u', $contents );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php

    r10277 r10429  
    6464        public function validate_content( $readme ) {
    6565
     66                // Security note: Keep the data: protocol here, Parser accepts a string HOWEVER
     67                // if a submitted readme.txt URL contents were to contain a file or URL-like string,
     68                // it could bypass the protections above in validate_url().
    6669                $readme = new Parser( 'data:text/plain,' . urlencode( $readme ) );
    6770
Note: See TracChangeset for help on using the changeset viewer.