Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

URI::MailTo::EMAIL_REGEXP matches whole strings but URI::RFC2396_PARSER.make_regexp matches partial strings

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
ruby
領域
api, backend

調査の方向性

公開エントリポイント URI::RFC2396_PARSER.make_regexp と URI::MailTo::EMAIL_REGEXP との相互作用を確認し、まず既存のマッチングセマンティクスと利用可能なテストを把握します。Done では、現在のデフォルト動作を維持しつつ、末尾の空白を拒否するカバレッジを備えた明示的な完全一致オプションを提供する必要があります。

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

説明

The way to test if a string is a valid email address is to directly use URI::MailTo::EMAIL_REGEXP

require 'uri'

puts URI::MailTo::EMAIL_REGEXP.match?('me@example.com') # true
puts URI::MailTo::EMAIL_REGEXP.match?('me@example.com ') # false (trailing space)

However, the correct way to validate that a string is a valid URL is to wrap the regex in anchors:

require 'uri'
puts /\A#{URI::RFC2396_PARSER.make_regexp}\z/.match?('https://example.com/') # true
puts /\A#{URI::RFC2396_PARSER.make_regexp}\z/.match?('https://example.com/ ') # false (trailing space)

If I directly use make_regexp, that second string matches because of a partial match.

require 'uri'
puts URI::RFC2396_PARSER.make_regexp.match?('https://example.com/ ') # true (trailing space)

Same behavior if I pass schemes into make_regexp or use the too. I'm on Ruby 4.0.1 but I don't think this behavior changed recently.

Would it be okay if I made a PR adding a keyword argument to make_regexp? It would get called like:

URI::RFC2396_PARSER.make_regexp(full_match: true).match?('https://example.com/ ') # true (trailing space)

I figured changing the default behavior could be a breaking change for a lot of people and that doesn't feel worth it.

主要言語
Ruby
スター
125
フォーク
65
平均マージ
6時間 4分
マージ済み PR(30日)
2

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

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

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

ruby/uri のほかの issue

ruby/uri の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

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

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