RegExp格式异常的格式不佳。

huangapple go评论51阅读模式
英文:

Poor formatting for RegExp format exception

问题

这是 Dart 3.0.3 的 macOS_x64 版本,在 Flutter 3.10.4 内部。

这段代码:

try {
    var re = RegExp(str, caseSensitive: false);
    // 对 're' 做一些操作
} on FormatException catch (e) {
    print("模式 '${str}' 导致 '${e}' ");
}

对于错误的名称模式如 ""[a-"

模式 '[a-' 导致 'FormatException: 未终止的字符类[a-' 

对我来说,它看起来需要在 'class' 后面和实际错误模式之前加上空格。使用 "${e.message}" 看起来同样糟糕。

我在这里做错了什么吗?
谢谢!

英文:

This is Dart 3.0.3 macos_x64, inside Flutter 3.10.4.

This code

  try {
    var re = RegExp(str, caseSensitive: false);
    // do something with 're'
  } on FormatException catch (e) {
    print("pattern '${str}' gives '${e}' ");
  }

gives this error on a bad name pattern like "[a-"

pattern '[a-' gives 'FormatException: Unterminated character class[a-' 

To me, it looks like it needs a space after 'class' and before the actual bad pattern. Using "${e.message}" looks just as bad.

Am I doing something wrong here?
Thanks!

答案1

得分: 1

这是Dart C++核心代码中的一个错误。 ReportError 将错误消息和模式连接在一起,但它们之间没有空格:

const String& msg = String::Handle(
      String::Concat(String::Handle(String::New(message)), in()));

而在这种情况下,message 是:

static const char* kUnterminated = "未终止的字符类";

请向他们报告这个错误。

英文:

This is a bug in the core Dart C++ code. ReportError concats together the error message and the pattern without a space between them:

const String& msg = String::Handle(
      String::Concat(String::Handle(String::New(message)), in()));

And in this case, message is:

static const char* kUnterminated = "Unterminated character class";

File a bug with them.

huangapple
  • 本文由 发表于 2023年6月13日 09:22:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76461164.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定