Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Add input validation for component name inputs #172

Open
Zaperex opened this issue Sep 15, 2023 · 2 comments
Open

Add input validation for component name inputs #172

Zaperex opened this issue Sep 15, 2023 · 2 comments

Comments

@Zaperex
Copy link
Member

Zaperex commented Sep 15, 2023

What needs to be done?

We need to add input validation for the component name inputs to ensure they satisfy the default format specified in the backstage architectural decisions docs:

  • Strings of length at least 1, and at most 63 (from testing, it's observed that it should actually be at most 62 chars)
  • Must consist of sequences of [a-z0-9A-Z] possibly separated by one of [-_.]

For this default format, we will need to add the following pattern validation for the input field:

properties:
  <propertyName>:
    title: Component Name
    type: string
    pattern: ^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$
    maxLength: 63

The 62 maxLength is because the catalog appears to actually not accept names that are 63 characters long.

- Tested with c0mponent-name_1234567890.abcdefghijklmnopqrstuvwxyz-abcdefghi_ which is exactly 63 chars long, but it got rejected.

- Tested with c0mponent-name_1234567890.abcdefghijklmnopqrstuvwxyz-abcdefghi, and it was accepted and ingested into the catalog/

This should prevent invalid names from being entered:
image
image
image

@Zaperex Zaperex changed the title Add input validation for component names Add input validation for component name inputs Sep 15, 2023
@Zaperex
Copy link
Member Author

Zaperex commented Sep 20, 2023

Correction: It seems I have misinterpreted the backstage entity name requirements. The [-_.] characters have to be used as separators not as leading or ending characters.
Which is why c0mponent-name_1234567890.abcdefghijklmnopqrstuvwxyz-abcdefghi_ doesn't work. However something like c0mponent-name_1234567890.abcdefghijklmnopqrstuvwxyz-abcdefghij will work.

@Zaperex
Copy link
Member Author

Zaperex commented Sep 20, 2023

Update: should be using ^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$ instead

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant