Skip to content

Improve yaml serialization quoting#4217

Draft
sigurdm wants to merge 1 commit intodart-lang:masterfrom
sigurdm:yaml_serialization
Draft

Improve yaml serialization quoting#4217
sigurdm wants to merge 1 commit intodart-lang:masterfrom
sigurdm:yaml_serialization

Conversation

@sigurdm
Copy link
Copy Markdown
Contributor

@sigurdm sigurdm commented Apr 11, 2024

#4214

We should only merge this if we want accept disturbing almost all pubspec.locks.

Maybe we can bundle it with another update to pubspec.lock structure.

We can also make a smalller update that just fixes bugs.

Copy link
Copy Markdown
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Drive-by-comments. I saw a regexp, so I had to say something.)

Comment thread lib/src/utils.dart
'null', 'Null', 'NULL',
].contains(s)) return true;
// Numbers must be quoted
if (RegExp(r'^[-+]?[0-9]*\.?[0-9]*(e[0-9]+)?$').hasMatch(s)) return true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a potentially dangerous RegExp because of the \d*\.?\d* sequence. It's probably not exponential, but it can be quadratic in the length to reject something like 00000000000000000000000....0000000x

Consider changing to \d*(\.\d*)? (And be aware that it still matches . alone.)

Comment thread lib/src/utils.dart
// Numbers must be quoted
if (RegExp(r'^[-+]?[0-9]*\.?[0-9]*(e[0-9]+)?$').hasMatch(s)) return true;
// Hex numbers must be quoted
if (RegExp(r'^0x[0-9]+$').hasMatch(s)) return true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be [0-9a-fA-F].

Comment thread lib/src/utils.dart
/// which means some strings may be unnecessarily quoted.
bool _needsYamlQuotes(String s) {
// These must be quoted
if ([
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List can be const. (Small save, but save, over creating a new list on every invocation.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants