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

Bb-code url is incorrectly converted if the value of the attribute href is not in quotes and there are parameters in the link #36

Closed
gnvcor opened this issue Jul 2, 2019 · 3 comments · Fixed by #50
Assignees
Labels
bug Something isn't working

Comments

@gnvcor
Copy link
Contributor

gnvcor commented Jul 2, 2019

From this bb-code: [url href=https://www.google.com?params=123]google[/url] I expect to receive a link of the form: <a href="https://www.google.com?params=123">google</a>.
But I get: <a href="" https://www.google.com?params="123">google</a>.

@JiLiZART JiLiZART self-assigned this Jul 2, 2019
@JiLiZART JiLiZART added the bug Something isn't working label Jul 2, 2019
@anvu69
Copy link

anvu69 commented Dec 25, 2019

Same issue!
My BBCode: [url]http://dantri.com.vn/.../20180724072628474.htm[/url]
And i receive tag: <a >http://dantri.com.vn/.../20180724072628474.htm</a> without href attrs.

But BBCode has type [url=http://dantri.com.vn/..../20180724072628474.htm]content....[/url], it return <a href="http://dantri.com.vn/..../20180724072628474.htm">content....</a> with href attrs!

Here is my code:

import bbob from '@bbob/core'
import { createPreset } from '@bbob/preset'
import { render } from '@bbob/html'
import _ from 'lodash'

const reduceAttr = (attrs) => {
  return _.reduce(
    attrs,
    (result, value, key) => {
      (result['attr'] || (result['attr'] = [])).push(value)
      return result.attr
    },
    {}
  )
}

const preset = createPreset({
  url: (node, { render }) => {
    return {
        tag: 'a',
        attrs: {
          href: reduceAttr(node.attrs) !== {}
            ? reduceAttr(node.attrs)[0]
            : render(node.content),
        },
        content: node.content
      }
  }
})

export default {
  convertBBCode (content) {
    if (content) {
      const result = bbob(preset()).process(content, { render }).html.replace(/(?:\r\n|\r|\n)/g, '<br>')
      return result
    } else {
      return ''
    }
  }
}

Update CodeSandbox link
Edit BBOB Bug

@JiLiZART
Copy link
Owner

Thanks for reporting! I take a look on this problem soon.
PS: You can use

import BBCode from '@bbob/react/es/Component'

instead of using html-react-parser

@ironsm4sh
Copy link

ironsm4sh commented Feb 26, 2020

I have a similar problem.
From the readme at bbob-parser. trying the example will parse into
image
instead of

[
    {
        "tag": "url",
        "attrs": {
            "url": "https://github.com"
        },
        "content": ["hello", " ", "world!"]
    }
]

The URL attribute is nowhere to be found, and a new attribute with the name of the url has appeared.

As a temporary fix, reverting back to version 1.3.2 works (but this breaks other things, such as the ability to use the enableEscapeTags option)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants