php / php/php-src

Replace the newlines in nl2br()

オープン
#15,845 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Extension: standard Feature Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

The function name of nl2br() suggests that it is a "replace" operation but is actually an "insert" operation.

Would it be possible to add a 3rd parameter so the function would actually replace the newline characters?

nl2br(string $string, bool $use_xhtml = true, bool $replace = false): string

The confusion with the name and the need for the 3rd parameter is obvious in the user contributed notes (most popular one and following ones): https://www.php.net/manual/en/function.nl2br.php#49516

The advantages of the 3rd parameter (instead of changing the behavior):

  • nl2br() would be idempotent when 3rd parameter is set to true. Today n2br() cannot be applied several times to a string without managing extra inserts.
  • Simplify the code. We could remove the wrappers to replace the newlines from our code.
  • Flexibility. Old behavior could be kept.
  • Backward compatible.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず php-src にある nl2br() の実装とそのテストを見つけ、現在の挿入動作と提案されている replace パラメータを比較します。3 番目のパラメータがデフォルトでは既存の動作を維持し、有効にした場合は改行文字を置換し、両方のモードをカバーするテストがある状態を完了とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
backend
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。