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

TemplateRegexMatcher.getStartRegex sometimes returns a regex that matches with an index before the license start

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
tooling

調査の方向性

TemplateRegexMatcher.getStartRegexから始め、issueにある両方のJava例を再現してください。オプションのセクションと貪欲な変数マッチがどのように開始正規表現へ変換されるかを追跡してください。完了条件は、オプション部分が存在する場合の正しい動作も含め、例が開始インデックス3と2を報告することです。

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

説明

matching

Version 1.1.11
Example 1 greedy regex after optional:

String licenseText = "ab cd text";
String licenseTemplate = "<<beginOptional>>cd<<endOptional>> <<var;name=\"copyright\";original=\"Copyright (c) <year> <copyright holders>  \";match=\".{0,5000}\">> text";
TemplateRegexMatcher templateRegexMatcher = new TemplateRegexMatcher(licenseTemplate);
String startRegex = templateRegexMatcher.getStartRegex(25);
System.out.println("start regex: " + startRegex);
Matcher matcher = Pattern.compile(startRegex).matcher(licenseText);
if (matcher.find()) {
    System.out.println("start index found: " + matcher.start());
}

Returns

start regex: (?im)(\Qcd\E\s*)?(.{0,5000})\Qtext\E\s*
start index found: 0

but the start index should be 3.

Example 2 greedy regex at start:

String licenseText = "abtext";
String licenseTemplate = "<<var;name=\"copyright\";original=\"Copyright (c) <year> <copyright holders>  \";match=\".{0,5000}\">> text";
TemplateRegexMatcher templateRegexMatcher = new TemplateRegexMatcher(licenseTemplate);
String startRegex = templateRegexMatcher.getStartRegex(25);
System.out.println("start regex: " + startRegex);
Matcher matcher = Pattern.compile(startRegex).matcher(licenseText);
if (matcher.find()) {
    System.out.println("start index found: " + matcher.start());
}

Returns

start regex: (?im)(.?{0,5000})\Qtext\E\s*
start index found: 1

but the start index should be 2.
.?{0,5000} doesn't seem to work as expected. It is an unusual regex that some online regex websites say is invalid: https://regex101.com/r/l3810b/1, regexr.com/81kfo.
https://www.freeformatter.com/java-regex-tester.html says the regular expression is valid.

I think maybe to fix this you could just offer a method for a regex to find the beginning of the non-optional part. Otherwise a changing the regular expressions in these two cases to something like the following could work

(?im)((\Qcd\E\s*)(.{0,5000})\Qtext\E\s*)|(\Qtext\E\s*)
(?im)\Qtext\E\s*

In the first case if there were multiple optional parts it would get even more complicated to do it correctly.

主要言語
Java
スター
71
フォーク
44
平均マージ
16時間 22分
マージ済み PR(30日)
9

環境構築

はじめの一歩

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

spdx/Spdx-Java-Library のほかの issue

spdx/Spdx-Java-Library の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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