Skip to content

Incorrect behavior of isBinary utilΒ #13829

@nickbullock

Description

@nickbullock

🐞 Bug report

Hi!

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [x] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

No.

Description

I'm trying to generate file from custom schema.
I've found incorrect behavior caused by @angular-devkit/schematics/src/rules/utils/is-binary.js
This function takes small chunks (24) of file and trying to detect is file binary or not.
So if file starts with string contains for example cyrrilic characters, isBinary will return incorrect result (true) because some symbols will be broken after cutting of 24 bits.
@schematics/angular/component/index.js
Call stack is rootFn => applyTemplates => applyContentTemplate => isBinary
I think this lib implements this function more correctly https://github.com/gjtorikian/isBinaryFile

πŸ”¬ Minimal Reproduction

I've builded https://github.com/angular/angular-cli/tree/master/packages/schematics/angular/component by tsc and then changed template of component schema (schematics/component/files/name@dasherize@if-flat/name@dasherize.component.ts.template), added these lines to top (comment block)

/**
 * @overview     Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―Π―
 * @copyright    Copyright (c) copyright, 2019
 */

and then run: ng g c foo

πŸ”₯ Exception or Error

Template file is not parsed because isBinary returned true, but it is not binary file

🌍 Your Environment




windows 10
node 10
"@angular-devkit/core": "^7.3.4",
"@angular-devkit/schematics": "^7.3.4",
"@angular/cli": "^7.3.4",
"@types/jasmine": "^3.0.0",
"@types/node": "^8.0.31"
"jasmine": "^3.0.0",
"typescript": "3.2.4"

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions