fix(@schematics/angular): allow dash in selector before a number#25253
fix(@schematics/angular): allow dash in selector before a number#25253alan-agius4 merged 1 commit intoangular:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
eb464f1 to
fdebed0
Compare
80abd64 to
5fe6cff
Compare
alan-agius4
left a comment
There was a problem hiding this comment.
Thanks for your contribution.
Can you please replace the E2E with a Unit test, similar to:
angular-cli/packages/schematics/angular/application/index_spec.ts
Lines 512 to 517 in e037dc9
Also, kindly update the commit message to
fix(@schematics/angular): allow dash in selector before a number
Closes #25164
5fe6cff to
b3d50ef
Compare
|
Hi @alan-agius4 , I have made the suggested changes but the setup step failed with |
|
Can you please clean you the commit message description and remove if you do want to add a description it should be before the |
b53f320 to
4dc8705
Compare
Done @alan-agius4. :) |
| // Must start with a letter, and must contain only alphanumeric characters or dashes. | ||
| // When adding a dash the segment after the dash must also start with a letter. | ||
| export const htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/; | ||
| export const htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*(:?-[0-9]+)*)*$/; |
There was a problem hiding this comment.
In some cases this regexp will fail to match
Example:
one-1
Maybe we can use the same logic as https://github.com/angular/angular-cli/blob/b66d94e5949102b2235b89cb75866973986ea30a/packages/angular_devkit/schematics/src/formats/html-selector.ts#L17C1-L44
//cc @clydin do you recall why we support upper characters as based on the spec it seems that these are not valid. https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
There was a problem hiding this comment.
Hi @alan-agius4 ,
It works when we create component with a general command like this: ng g c one-1. In this case, the final selector becomes: app-one-1 which is valid for this regexp. Assuming that the default prefix app is being used.
However, it does not work with following command: ng g c one-1 --selector one-1 because it tries to override the default naming convention of selector in which prefix is added initially.
I will cover this scenario in my next commit and will update.
There was a problem hiding this comment.
@alan-agius4 Found another problem. If we allow one-1 like selectors then it will also verify app-1-one as valid and in that case, the component class name becomes like this: -
export class 1OneComponent {
}
This is invalid class name. Isn't it?
So, I might have to add some conditions that regexp doesn't allow 1-one if the component is being created with a prefix which will ultimately become app-1-one.
4dc8705 to
d6c4610
Compare
d6c4610 to
55392c4
Compare
| // When adding a dash the segment after the dash must also start with a letter. | ||
| export const htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/; | ||
| export const htmlSelectorRe = | ||
| /^[a-zA-Z][.0-9a-zA-Z]*((:?-[0-9]+)*|(:?-[a-zA-Z][.0-9a-zA-Z]*(:?-[0-9]+)*)*)$/; |
There was a problem hiding this comment.
Regexp used here doesn't validate html selector correctly. For eg., it considers foo- as a valid selector which is wrong, right? And it also allows underscore.
I have modified regexp in validation.ts file itself to cover selectors like one-1 but if we still want to use the logic at html-selector.ts then we might have to make some changes in that logic.
55392c4 to
a7e1943
Compare
This commit updates the validator regexp to allow a dash before a number. Closes angular#25164
a7e1943 to
6c4c56e
Compare
|
Hi @alan-agius4, I have made some changes. Could you please review this? |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes #25164
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Does not allow dash in selector before a number. Which means, following command would throw error: -
ng g c TodoItemTask-123Issue Number: #25164
What is the new behavior?
Command like this will work: -

ng g c TodoItemTask-123Does this PR introduce a breaking change?
Other information