File tree 4 files changed +20
-2
lines changed
packages/schematics/angular
4 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import {
25
25
import { addDeclarationToNgModule } from '../utility/add-declaration-to-ng-module' ;
26
26
import { findModuleFromOptions } from '../utility/find-module' ;
27
27
import { parseName } from '../utility/parse-name' ;
28
- import { validateHtmlSelector } from '../utility/validation' ;
28
+ import { validateClassName , validateHtmlSelector } from '../utility/validation' ;
29
29
import { buildDefaultPath , getWorkspace } from '../utility/workspace' ;
30
30
import { Schema as ComponentOptions , Style } from './schema' ;
31
31
@@ -62,6 +62,7 @@ export default function (options: ComponentOptions): Rule {
62
62
options . selector || buildSelector ( options , ( project && project . prefix ) || '' ) ;
63
63
64
64
validateHtmlSelector ( options . selector ) ;
65
+ validateClassName ( strings . classify ( options . name ) ) ;
65
66
66
67
const skipStyleFile = options . inlineStyle || options . style === Style . None ;
67
68
const templateSource = apply ( url ( './files' ) , [
Original file line number Diff line number Diff line change @@ -157,6 +157,14 @@ describe('Component Schematic', () => {
157
157
) . toBeRejectedWithError ( 'Selector "app-1-one" is invalid.' ) ;
158
158
} ) ;
159
159
160
+ it ( 'should error when class name contains invalid characters' , async ( ) => {
161
+ const options = { ...defaultOptions , name : '404' } ;
162
+
163
+ await expectAsync (
164
+ schematicRunner . runSchematic ( 'component' , options , appTree ) ,
165
+ ) . toBeRejectedWithError ( 'Class name "404" is invalid.' ) ;
166
+ } ) ;
167
+
160
168
it ( 'should allow dash in selector before a number' , async ( ) => {
161
169
const options = { ...defaultOptions , name : 'one-1' } ;
162
170
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ import {
23
23
import { addDeclarationToNgModule } from '../utility/add-declaration-to-ng-module' ;
24
24
import { findModuleFromOptions } from '../utility/find-module' ;
25
25
import { parseName } from '../utility/parse-name' ;
26
- import { validateHtmlSelector } from '../utility/validation' ;
26
+ import { validateClassName , validateHtmlSelector } from '../utility/validation' ;
27
27
import { buildDefaultPath , getWorkspace } from '../utility/workspace' ;
28
28
import { Schema as DirectiveOptions } from './schema' ;
29
29
@@ -58,6 +58,7 @@ export default function (options: DirectiveOptions): Rule {
58
58
options . selector = options . selector || buildSelector ( options , project . prefix || '' ) ;
59
59
60
60
validateHtmlSelector ( options . selector ) ;
61
+ validateClassName ( strings . classify ( options . name ) ) ;
61
62
62
63
const templateSource = apply ( url ( './files' ) , [
63
64
options . skipTests ? filter ( ( path ) => ! path . endsWith ( '.spec.ts.template' ) ) : noop ( ) ,
Original file line number Diff line number Diff line change @@ -111,6 +111,14 @@ describe('Directive Schematic', () => {
111
111
expect ( directiveContent ) . toContain ( 'class FooDirective' ) ;
112
112
} ) ;
113
113
114
+ it ( 'should error when class name contains invalid characters' , async ( ) => {
115
+ const options = { ...defaultOptions , name : '404' } ;
116
+
117
+ await expectAsync (
118
+ schematicRunner . runSchematic ( 'component' , options , appTree ) ,
119
+ ) . toBeRejectedWithError ( 'Class name "404" is invalid.' ) ;
120
+ } ) ;
121
+
114
122
describe ( 'standalone=false' , ( ) => {
115
123
const defaultNonStandaloneOptions : DirectiveOptions = {
116
124
...defaultOptions ,
You can’t perform that action at this time.
0 commit comments