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

Cannot parse URLs with = #14

Open
ghost opened this issue Oct 21, 2014 · 3 comments
Open

Cannot parse URLs with = #14

ghost opened this issue Oct 21, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 21, 2014

When you try to parse a URL, let's say

[url=newsattachment.php?id=23]attachment[/url]

that doesn't work.

THX in advance.

@Khalilbz
Copy link

The final solution it's working 100% but it needs some optimizations ^_^

In the classes/Node/Container/Document.php
change the parse function header to be like that

public function parse($str)
    {
        //$str      = preg_replace('/[\r\n|\r]/', "\n", $str);
        //This is the added code
        $bbstr = $str;
        $result = "";
        while (strpos($bbstr, "[url=") !== false) {
            $pos = strpos($bbstr, "[url=")+5;
            $result .= substr($bbstr,0,$pos);
            $bbstr = substr($bbstr,$pos,strlen($bbstr));
            $pos = strpos($bbstr, "]")-1;
            $link = substr($bbstr,0,$pos+1);if($pos<0)$link="#";
            $link = str_replace('=',"IXI_SBBCODEPARSER_URL_PROBLEM_IS_SOLVED",$link);
            $bbstr = substr($bbstr,$pos+1,strlen($bbstr));
            $result .= $link;
        }
        $result .= $bbstr;
        $str = $result;//The added code ends here


        $len      = strlen($str);
        $tag_open = false;
        $tag_text = '';
        $tag      = '';
...

And in the classes/Node/Container.php
change the function get_html() to oldget_html() then add this function :

/**
    *
    * @return string
    */
    public function get_html($nl2br=true){
        return str_replace("IXI_SBBCODEPARSER_URL_PROBLEM_IS_SOLVED",'=',$this->oldget_html($nl2br));
    }

and now every thing will run without any problem

Suggestion : I think that we can use @diegargon solution if we will be able to specify the tag ([URL]) in the IF statement

@clemenswagner
Copy link

clemenswagner commented Sep 2, 2016

There are actually two problems with link parsing. SBBCodeParser doesn't like equal signs in urls, and it prepends the base uri in front of paths even if the path begins with '/'. I have fixed this with the following patch:

--- Document.orig.php   2013-08-02 20:21:57.000000000 +0200
+++ Document.php    2016-09-02 07:31:41.000000000 +0200
@@ -553,7 +553,8 @@
                if(strpos($attribs['default'], 'www') === 0)
                    $attribs['default'] = 'http://' . $attribs['default'];
                // add the base url to any urls not starting with http or ftp as they must be relative
-               else if(substr($attribs['default'], 0, 4) !== 'http'
+               else if($attribs['default'][0] !== '/'
+                   && substr($attribs['default'], 0, 4) !== 'http'
                    && substr($attribs['default'], 0, 3) !== 'ftp')
                    $attribs['default'] = $node->root()->get_base_uri() . $attribs['default'];

@@ -875,7 +876,7 @@

        // if this tag only has one = then there is only one attribute
        // so add it all to default
-       if($attribs[0] == '=' && strrpos($attribs, '=') === 0)
+       if($attribs[0] == '=' && (strpos($attribs, ' ') == null || strrpos($attribs, '=') === 0))
            $ret['default'] = htmlentities(substr($attribs, 1), ENT_QUOTES | ENT_IGNORE, "UTF-8");
        else
        {

@0xbadc0de
Copy link

I do not know whether the topic is relevant. But check out pull request #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants