Skip to content

Unespected space at beginning of link text #168

Open

Description

@neffets

I was irritated by text from an editor. Why it does not generate correct links?

The raw text was:

E-Mail: " name":mailto:test@test.de

it generates as html output

<a href="mailto:test@test.de">E-Mail: “ name</a>

Until I found: the link-text begins with a space.
I expected as output:

E-Mail: <a href="mailto:test@test.de"> name</a>

or

E-Mail: <a href="mailto:test@test.de">name</a>

Why we cannot accept spaces at beginning of link-text? (came from paste and copy) And it made a typographic quote from it.

Activity

  1. neffets commented on Jul 11, 2016

    @neffets
    Author

    combined bug. if a second line have a broken link (caused by space-linktext),
    then a former correct link will be broken too

    e.g.

    * "Bauordnung für Berlin":http://www.stadtentwicklung.berlin.de/service/gesetzestexte/de/bauen.shtml
    * " Verwaltungsverfahrensgesetz":http://www.gesetze-im-internet.de/vwvfg/BJNR012530976.html
    

    will get you two broken / not-evaluated links. line one alone will get you an correct evaluated link.

  2. eliph commented on Jul 14, 2016

    @eliph

    Broken syntax will generate broken code, in any language.

  3. added a commit that references this issue on Jul 21, 2016
  4. netcarver commented on Jul 21, 2016

    @netcarver
    Contributor

    @neffets I've just pushed a new branch with a partial fix for this. Could you try out the issue-168 branch and let me know how that works for you. Could you please also verify that the issue you reported in #167 still exists in that branch.

    Many thanks!

  5. netcarver commented on Jul 23, 2016

    @netcarver
    Contributor

    @eliph I'd like to make the handling of this case more robust if I can - but I agree with your sentiment here.

  6. netcarver commented on Jul 25, 2016

    @netcarver
    Contributor

    @eliph @neffets - I've pushed an update to the issue-168 branch (link mentioned above) that should improve the detection of the start-of-link quote. Would appreciate if folks would test test this.

  7. 5 remaining items

  8. added a commit that references this issue on Jul 28, 2016
  9. netcarver commented on Jul 28, 2016

    @netcarver
    Contributor

    @neffets Just pushed a correction that should cover this case. Please test again.

  10. eliph commented on Jul 28, 2016

    @eliph

    @netcarver: Generally I would not not consider bad usage of the Textile syntax a "bug", as already pointed out. Hopefully, this change will not result in breaking other, complex situations where Textile is used correcly.

  11. netcarver commented on Jul 28, 2016

    @netcarver
    Contributor

    Hi @eliph - this has not caused any of the existing test cases to fail. It also makes php-textile more resilient to typos in otherwise correct link text. If you know of any examples that this change would negatively impact, please make them known so I can include them in the test cases and work towards getting them fixed.

  12. neffets commented on Jul 28, 2016

    @neffets
    Author

    Thanx @eliph , with last commit it is now working completely, all links work.

  13. netcarver commented on Jul 28, 2016

    @netcarver
    Contributor

    @neffets Thank you for testing that. I'll leave this open a few more days in case there is more feedback.

  14. self-assigned this
    on Nov 17, 2016
  15. neffets commented on Oct 9, 2018

    @neffets
    Author

    Hello, i tried v3.6.0 it fixes issue #167, but issue #168 has still problems.

    Example-1:

    " Line 1":/test/
    " Line 2":/test/
    " Line 3":/test/`

    Example-2:

    "Line 1":/test/
    " Line 2":/test/
    " Line 3":/test/

    I need a little patch in line 3630 like former issue-168 patch

    patch.Netcarver_Textile_Parser-118.txt

    --- vendor/netcarver/textile/src/Netcarver/Textile/Parser.php-3.6.0	2018-10-09 09:23:42.792001373 +0000
    +++ vendor/netcarver/textile/src/Netcarver/Textile/Parser.php	2018-10-09 15:38:24.667558319 +0000
    @@ -3627,16 +3627,27 @@
                         }
                     }
     
    -                // Rebuild the link's text by reversing the parts and sticking them back
    -                // together with quotes.
    -                $link_content = implode('"', array_reverse($linkparts));
    - 
    -                // Rebuild the remaining stuff that goes before the link but that's
    -                // already in order.
    -                $pre_link = implode('"', $possible_start_quotes);
    - 
    -                // Re-assemble the link starts with a specific marker for the next regex.
    -                $slice = $pre_link . $this->uid.'linkStartMarker:"' . $link_content;
    +                if ($balanced > 0) {
    +                    // We found more end-quotes than start quotes. We can try to correct this if there are 'ambiguous' quotes
    +                    // present. Ambiguous quotes are quotes that appear with spaces on each side - such that they are not
    +                    // obviously a start or an end quote.
    +                    $replaced = 0;
    +                    $slice = preg_replace('~ +" +~'.$mod, ' '.$this->uid.'linkStartMarker:"', $slice, 1, $replaced);
    +                    if ($replaced == 0) {
    +                        $slice = preg_replace('~^" +~m'.$mod, $this->uid.'linkStartMarker:"', $slice, 1, $replaced);
    +                    }
    +                } else {
    +                    // Rebuild the link's text by reversing the parts and sticking them back
    +                    // together with quotes.
    +                    $link_content = implode('"', array_reverse($linkparts));
    + 
    +                    // Rebuild the remaining stuff that goes before the link but that's
    +                    // already in order.
    +                    $pre_link = implode('"', $possible_start_quotes);
    + 
    +                    // Re-assemble the link starts with a specific marker for the next regex.
    +                    $slice = $pre_link . $this->uid.'linkStartMarker:"' . $link_content;
    +                }
                 }
     
                 // Add the last part back
    
  16. added a commit that references this issue on Jun 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions