# BBCodeの\`url\`タグは、テキストがホストの後にコンポーネントを持つURLで終わる場合に壊れます

**URL:** https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448
**Category:** Bug
**Created:** [2023 年 4 月 20 日午後 11:54 UTC](https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448 "2023-04-20T23:54:47Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![per1234](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/per1234/32/569645_2.png) [@per1234](https://meta.discourse.org/u/per1234)
#### Post date: [2023 年 4 月 20 日午後 11:54 UTC](https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448/1 "2023-04-20T23:54:47Z")

</div>

### 優先度/重大度:

中

### プラットフォーム

| OS | ブラウザ |
| --- | --- |
| Windows 11 | Google Chrome 112.0.5615.138 |
| Ubuntu 22.04 | Google Chrome 112.0.5615.49 |
| macOS Ventura | Google Chrome 112.0.5615.137 |

(すべてデスクトップ)

### 説明:

以下の条件下で、投稿内の[BBCode](https://www.bbcode.org/reference.php) `url` タグが正しくレンダリングされません。

- タグで囲まれたテキストがURLで終わる
- そのURLがホストコンポーネントの後にコンポーネントを持つ（つまり、[パス](https://en.wikipedia.org/wiki/URL#path)、[クエリ](https://en.wikipedia.org/wiki/URL#query)、および/または[フラグメント](https://en.wikipedia.org/wiki/URL#fragment)）

### 再現手順:

以下のマークアップを含む投稿を作成します。

```bbcode
[url]http://example.com/[/url]

```

🐛 マークアップが期待どおりにレンダリングされません。

![image](https://global.discourse-cdn.com/meta/original/4X/d/b/d/dbd187c3df3f7131ca5e04be76920cbd0198c338.png)

#### 期待される動作:

マークアップは次のようにレンダリングされるべきです。

![image](https://global.discourse-cdn.com/meta/original/4X/9/c/f/9cf5978e4785a9e8f5c3049a02cb19bc60964771.png)

### 追加コンテキスト

[try.discourse.org](http://try.discourse.org) の “[セーフモード](https://meta.discourse.org/t/how-to-use-discourse-safe-mode/53504)” でこの問題を再現できました。

* * *

パスで終わるURLのテキストの誤処理の追加例:

マークアップ:

```bbcode
[url]http://example.com/foo[/url]
[url]http://example.com/foo/[/url]
[url=http://example.com/]http://example.com/[/url]
[url=http://example.com/]foo http://example.com/[/url]

```

レンダリング:

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/d/f/8df8024484aaab316b8fa9fc9ef25633b2de7897.png)

* * *

[Old url markup not migrated to new forum - Website and Forum - Arduino Forum](https://forum.arduino.cc/t/old-url-markup-not-migrated-to-new-forum/1117448) で最初に報告されました。

このマークアップが正しくレンダリングされていた時期（[SMF](https://www.simplemachines.org/) フレームワークから Discourse への移行前）に作成された投稿が多数あります。

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2023 年 4 月 21 日午前 6:38 UTC](https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448/2 "2023-04-21T06:38:21Z")

</div>

これはコアバグとして確認されており、今後数週間で修正する予定です。

具体的には、

`[url]http://example.com[/url]` は機能しますが、`[url]http://example.com/example[/url]` は末尾にスペースを追加しない限り機能しません `[url]http://example.com/example [/url]` 。

デバッグを開始したところ、エスケープルールが原因でパーサーがトリップしているようです。修正いたしますので、ご報告ありがとうございました。

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2023 年 4 月 21 日午後 6:54 UTC](https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448/7 "2023-04-21T18:54:48Z")

</div>

このコードにはあまり詳しくありませんが、ざっと見てみました。自動リンクシステムに関係していると思います。パーサーが終了URLタグ `[/url]` を探す頃には、それはすでに自動リンクに組み込まれています。

例：ここの自動リンクが `http://example.com/foo%5B/url%5D` になっていることに注意してください。

[http://example.com/foo](http://example.com/foo)

だから、スペースを追加すると役立つのは、自動リンクに `[/url]` が含まれるのを防ぐためです。

🤔

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2023 年 4 月 24 日午前 4:45 UTC](https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448/9 "2023-04-24T04:45:44Z")

</div>

以下のように修正しました。

> <https://github.com/discourse/discourse/pull/21215>
>
> Due to the order we were parsing markdown, bbcode \[url\] elements were not
> handle…d properly.
> 
> \`\[url\]https://example.com/path\[/url\]\` was not currectly parsing cause
> linkify was detecting the url as: \`https://example.com/path\[/url\]\` which is
> legit.
> 
> To resolve this I swapped url to use a replace rule, and instead re-parsed
> the internal payload and injected the tokens in.
> 
> This fix is complex cause we support stuff like
> 
> \`\[url\]\[b\]test.com\[/b\]\[/url\]\`
> 
> So we need to parse the content inside url \`\[b\]test.com\[/b\]\`

レビュー/マージをどうぞ。これは非常に複雑な修正です @per1234 なぜなら、以下のようなクレイジーなものもサポートしているからです。

`[url][b]www.site.com[/b][/url]`

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2023 年 4 月 25 日午後 8:29 UTC](https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448/13 "2023-04-25T20:29:29Z")

</div>

これで全て修正されました 🎊

```plaintext
[url]http://example.com/foo[/url]
[url]http://example.com/foo/[/url]
[url=http://example.com/]http://example.com/[/url]
[url=http://example.com/]foo http://example.com/[/url]

```

[http://example.com/foo](http://example.com/foo)  
[http://example.com/foo/](http://example.com/foo/)  
[http://example.com/](http://example.com/)  
[foo http://example.com/](http://example.com/)

@per1234  
修正は既にデプロイされているはずです。問題なく動作しているか教えてください！

ご報告ありがとうございました！

---

<div class="post-metadata">

### Author: ![per1234](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/per1234/32/569645_2.png) [@per1234](https://meta.discourse.org/u/per1234)
#### Post date: [2023 年 4 月 27 日午前 3:29 UTC](https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448/14 "2023-04-27T03:29:04Z")

</div>

**サム** さん、迅速な解決をありがとうございます！

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2023 年 4 月 30 日午後 10:00 UTC](https://meta.discourse.org/t/bbcode-url-tags-break-if-wrapped-text-ends-in-url-with-component-after-host/262448/15 "2023-04-30T22:00:03Z")

</div>

このトピックは5日後に自動的に閉じられました。返信はもう許可されていません。
