Skip to content
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

schematics: inputs should be sanitized #104

Closed
timdeschryver opened this issue Dec 27, 2019 · 7 comments
Closed

schematics: inputs should be sanitized #104

timdeschryver opened this issue Dec 27, 2019 · 7 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@timdeschryver
Copy link
Contributor

timdeschryver commented Dec 27, 2019

🐞 Bug report

Description

The inputs for the schematics to create a post or markdown should be sanitized.

🔬 Minimal Reproduction

The following command generated a new post as /blog/first/post.md, the post will not be found in this case.

ng g @scullyio/init:post --name="first/post"

A similar thing happens to the markdown schematic, this command creates invalid JSON in the config:

ng g @scullyio/init:markdown --name=my-test! --slug=my-test!
exports.config = {
  projectRoot: "./src/app",
  routes: {
    '/my-test!/:my-test!': {
      type: 'contentFolder',
      my-test!: {
        folder: "./my-test!"
      }
    }
  }
};

💻Your Environment

Angular Version:


Latest

Scully Version:


Latest

🔥 Exception or Error


@timdeschryver timdeschryver added the bug Something isn't working label Dec 27, 2019
@SanderElias SanderElias added this to the pre beta milestone Dec 31, 2019
@d-koppenhagen
Copy link
Contributor

d-koppenhagen commented Jan 11, 2020

#177 should face this issue. I created some more tests check the options will be dasherized / camelized / normalized

@d-koppenhagen
Copy link
Contributor

But I checked it again: special chars like "!" will still be kept. They should be filtered.

@d-koppenhagen
Copy link
Contributor

d-koppenhagen commented Jan 11, 2020

I think replacing all special chars except _ should be used additionally for dasherized and camelized parts:

const final = original.replace(/[^a-zA-Z-]/g, '');

And replacing all special chars except / and - should be used additionally for the route parts parts:

const final = original.replace(/[^a-zA-Z\/-]/g, '');

@d-koppenhagen
Copy link
Contributor

I think there are two possibly ways to handle this:
a) filter all non numeric or ASCII characters and remove them except in a generated markdown file
b) throw an exception (The the way how it's handled by e.g. ng g c foo!)

@jorgeucano what do you think?

@jorgeucano
Copy link
Contributor

fixed in the new version :)

@d-koppenhagen
Copy link
Contributor

@jorgeucano shouldn't toAscii also be applied to the route option?

@d-koppenhagen
Copy link
Contributor

d-koppenhagen commented Jan 21, 2020

sent a PR: #210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants