Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unespected space at beginning of link text #168

Open
neffets opened this issue Jul 10, 2016 · 12 comments
Open

Unespected space at beginning of link text #168

neffets opened this issue Jul 10, 2016 · 12 comments

Comments

@neffets
Copy link

neffets commented Jul 10, 2016

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

The raw text was:

E-Mail: " name":mailto:[email protected]

it generates as html output

<a href="mailto:[email protected]">E-Mail: “ name</a>

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

E-Mail: <a href="mailto:[email protected]"> name</a>

or

E-Mail: <a href="mailto:[email protected]">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.

@neffets
Copy link
Author

neffets commented Jul 11, 2016

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.

@eliph
Copy link

eliph commented Jul 14, 2016

Broken syntax will generate broken code, in any language.

netcarver pushed a commit that referenced this issue Jul 21, 2016
Allow link text to start with a space.
@netcarver
Copy link
Contributor

netcarver commented Jul 21, 2016

@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!

@netcarver
Copy link
Contributor

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

@netcarver
Copy link
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.

@neffets
Copy link
Author

neffets commented Jul 27, 2016

Tested the "issue-168" branch.

It accepts the first link with a space at begin of the linktext.
But only the frist. I You sets such an link in line-1, line-2 and line-3 - only the first line will be recognized and changed to a link.

With "issue-168" branch the line-2 and line-3 remains untouched


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

generates source code

<a href="/test/">Line 1</a><br />
&#8220; Line 2&#8221;:/test/<br />
&#8220; Line 3&#8221;:/test/<br />

Bug #167 is fixed in this branch, it works

netcarver pushed a commit that referenced this issue Jul 28, 2016
@netcarver
Copy link
Contributor

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

@eliph
Copy link

eliph commented Jul 28, 2016

@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.

@netcarver
Copy link
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.

@neffets
Copy link
Author

neffets commented Jul 28, 2016

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

@netcarver
Copy link
Contributor

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

@netcarver netcarver self-assigned this Nov 17, 2016
@neffets
Copy link
Author

neffets commented Oct 9, 2018

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

neffets pushed a commit to berlinonline/php-textile that referenced this issue Jan 3, 2019
gocom added a commit that referenced this issue Jun 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants