Phpdocumentor: 3.0.0: slashes in strings display escaped/doubled

Created on 15 Jun 2020  路  5Comments  路  Source: phpDocumentor/phpDocumentor

Given the following piece of code in file src/issue-2421.php:

<?php
class Issue2421 {
    /**
     * Regular expression to check if a given identifier name is valid for use in PHP.
     *
     * @var string
     */
    const PHP_LABEL_REGEX = '`^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$`';
}


with the following config:

<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
    configVersion="3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://www.phpdoc.org"
    xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
    <title>Demo</title>
    <version number="latest">
        <api format="php">
            <source dsn=".">
                <path>src</path>
            </source>
        </api>
    </version>
    <template name="default"/>
</phpdocumentor>

Expected behavior

I'd expect to see the constant value to be displayed as declared in the code.

Actual behavior

The slashes in the constant value are displayed as double slashed.

issue-2421

As found in project

Steps to reproduce the problem

  1. Issue can be reproduced with the above code sample and config or via the linked project.
  2. Run php -f /path/to/phpDocumentor/bin/phpdoc

Your environment

bug

All 5 comments

Investigated the issue and it seems to be related to the passing of this value into the templates and not with the template itself. As discussed with @jaapio, I am skipping any issue not related to the templates at the moment

This issue goes even deeper than phpDocumentor itself.
We are using the PrettyPrinter of PHP-Parser to convert values to there respective value.
This is also the reason why default values of properties are losing there newlines. The values are tokenized and parsed as they are normal statements. This means that we are not reading code but stringified tokens. Which do not have any newlines.

Fixing this could be tricky... I'm going to remove the slashes manually for now. This issue might return for other values. Which needs to be checked as well.

This issue should be fixed now for:

  • property default values
  • method argument default values
  • constant values

I didn't check if this issue also exists in docblock values since we are not using php-parser to print those.

@jaapio Thank you so much!

@jaapio Hmm.. just noticed... when a single backslash is used in a non-text string context, like when using a FQN constant \T_IF in a property declaration, that single backslash is now also removed...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adjenks picture adjenks  路  5Comments

joshmbg picture joshmbg  路  5Comments

h0gar picture h0gar  路  4Comments

ajthinking picture ajthinking  路  4Comments

neooblaster picture neooblaster  路  4Comments