-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router_builder] Removes path_to_regexp from the dependencies
#4517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ValentinVignal
wants to merge
2
commits into
flutter:main
from
ValentinVignal:go-router-builder/remove-path-to-regexp-from-dependencies
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| /// The base type of all tokens produced by a path specification. | ||
| abstract class Token { | ||
| /// The name of the parameter. | ||
| String get name; | ||
|
|
||
| /// Parses a [path] specification. | ||
| static List<Token> parse(String path) => _parse(path); | ||
| } | ||
|
|
||
| /// Corresponds to a parameter of a path specification. | ||
| class ParameterToken implements Token { | ||
| /// Creates a parameter token for [name]. | ||
| ParameterToken(this.name); | ||
|
|
||
| /// The parameter name. | ||
| @override | ||
| final String name; | ||
| } | ||
|
|
||
| /// Corresponds to a non-parameterized section of a path specification. | ||
| class PathToken implements Token { | ||
| /// Creates a path token with [name]. | ||
| PathToken(this.name); | ||
|
|
||
| /// A substring of the path specification. | ||
| @override | ||
| final String name; | ||
| } | ||
|
|
||
| /// The regular expression used to extract parameters from a path specification. | ||
| /// | ||
| /// Capture groups: | ||
| /// 1. The parameter name. | ||
| /// 2. An optional pattern. | ||
| final RegExp _parameterRegExp = RegExp( | ||
| /* (1) */ r':(\w+)' | ||
| /* (2) */ r'(\((?:\\.|[^\\()])+\))?', | ||
| ); | ||
|
|
||
| /// Parses a [path] specification. | ||
| List<Token> _parse(String path) { | ||
| final Iterable<RegExpMatch> matches = _parameterRegExp.allMatches(path); | ||
| final List<Token> tokens = <Token>[]; | ||
| int start = 0; | ||
| for (final RegExpMatch match in matches) { | ||
| if (match.start > start) { | ||
| tokens.add(PathToken(path.substring(start, match.start))); | ||
| } | ||
| final String name = match[1]!; | ||
| tokens.add(ParameterToken(name)); | ||
| start = match.end; | ||
| } | ||
| if (start < path.length) { | ||
| tokens.add(PathToken(path.substring(start))); | ||
| } | ||
| return tokens; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is very much inspired by
path_to_regexplibrary, I don't know if I'm allowed to do thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "inspired by" mean? If you read the source of that package as part of writing this implementation, then no, that would disqualify you from contributing an implementation (in which case this PR should be closed).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did read the package source code to understand what was actually happening and how
go_router_builderwas using it.I guess the PR cannot be merged as it is right now. Before closing it, let me try to clean it out and re-write something else.
But
go_router_builderalready has its methods built around it so it might end up looking similar anywayThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot unsee the implementation, so any implementation you write will not be a clean room implementation, and would not satisfy licensing requirements.
Someone else will need to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I cannot work on this issue anymore? 😕
What if I find another way to code it that is not similar to the package? Would that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. We need a clean room implementation of the functionality this package needs, and you cannot provide that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if as I suggested the implementation's logic is completely different? What would be the issue with that since it would explicitly not be inspired by the package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a lawyer, and I have no interest in unnecessarily involving lawyers in the process of fixing the referenced issue.