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

DataType.fromValue has false positives for guids #79

Open
thcgit opened this issue Aug 17, 2023 · 1 comment
Open

DataType.fromValue has false positives for guids #79

thcgit opened this issue Aug 17, 2023 · 1 comment

Comments

@thcgit
Copy link

thcgit commented Aug 17, 2023

The following unit tests fails on version 2.1.5:

  test("example", () => {
    expect(DataType.fromValue("foo")).toBe(DataType.String);
    expect(DataType.fromValue("f16fb858-1e02-46fb-8467-a5fb45a7067f")).toBe(
      DataType.Guid
    );
    expect(DataType.fromValue("foo-f16fb858-1e02-46fb-8467-a5fb45a7067f")).toBe(
      DataType.String
    );
  });

The 3rd expectation fails - fromValue returns DataType.Guid, which is probably not the correct behavior.

The problem seems to be in core.ts where the isGuid function uses a regular expression without a start or end anchor:

function isGuid(value: any) {
  return (typeof value === "string") && /[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}/.test(value);
}

I tried to create a pull request to fix this but ran into a few issues:

  1. There's no package-lock.json in the root of the repo so I'm unsure if npm installed compatible package versions.
  2. The build command failed on the downlevel-dts step, possibly due to some incompatible package version.
  3. When running the unit tests, many tests fail trying to make http requests to services like http://localhost:34377/breeze/NorthwindIBModel/Metadata. Is there a script for spinning up the services required for tests, or documentation on how to set them up?
@steveschmitt
Copy link
Member

Good catch! Thanks for that.

Sorry about the missing package-lock.json. The versions in package.json should have been sufficient to create a reliable build, but apparently that's not the case.

The unit tests require spinning up a server separately, using the code in the breeze.server.net repo.

steveschmitt added a commit that referenced this issue Jan 3, 2024
 - Move regex definitions outside of functions in core.ts, to allow JS to keep compiled versions
 - Add spec for `hour` function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants