parser-js icon indicating copy to clipboard operation
parser-js copied to clipboard

feat: parseFromUrl does not resolve relative references (#504)

Open aeworxet opened this issue 3 years ago • 2 comments

This PR resolves issue #504.

  • getBaseUrl() was made a separate util to make code reuse possible.
  • URL validation in it is not performed because node-fetch performs its own validation at fetch time, so no repetition of this task is made. The function only ensures that url has type of string and lets node-fetch deal with the rest.
  • Condition (typeof window !== 'undefined' && !options.hasOwnProperty('path')) was added for the case if getBaseUrl() gets called directly from inside of a browser (not from parseFromUrl(), but from <script>) AND, amongst all, object options doesn't already have in it its own property path with value. It is assumed in this case that getBaseUrl() was not executed yet, so it's executed. If getBaseUrl() gets called from inside of a browser AND object options HAS in it its own property path with a value - OK then, somehow it got that value, so getBaseUrl() does not get executed. This construction was inspired by test 'parse from string' in ./test/sample_browser/index.html. It is also assumed that, at the end of the day, user could have provided his own version of options.path - injected it at some point, for example.
  • </> in <anonymous-schema-x> were considered custom HTML tags by browser's parser and didn't appear on screen making automated tests that assert visible elements' content to fail. So they are changed to HTML entities &lt;/&gt; before insertion into the DOM and are replaced back to </> by browser's parser at the insertion time, thus allowing automated tests querying elements' content to pass.
  • Assertion tests are made big intentionally, so they test big chunks of functionality at once, and if the test fails, one, using difftool, can quickly peek what was parsed wrong and get an idea of where to look.
  • Updated puppeteer to latest version (v17.0.0 at the moment of writing) just to make it more up to date.

aeworxet avatar Jul 19 '22 14:07 aeworxet

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Jul 20 '22 14:07 sonarqubecloud[bot]

@derberg Fixed.

aeworxet avatar Sep 01 '22 12:09 aeworxet

We are facing same issue, so curious to know when this PR could be merged and available to use?

tapan3 avatar Sep 08 '22 08:09 tapan3

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Sep 14 '22 08:09 sonarqubecloud[bot]

@derberg are we waiting for other people to review it as well or can we merge it? 🤔

jonaslagoni avatar Sep 14 '22 11:09 jonaslagoni

@jonaslagoni no, I was most interested with your input as you did report the related issue.

we just need to update PR description properly so GitHub closes related issues.

So, you think we can close #344 with this one too?

You right, yea, I think we can, at least that's what I am gonna do 👍

jonaslagoni avatar Sep 14 '22 11:09 jonaslagoni

@aeworxet just added the following to automatically close the issues once released 🙂

Fixes https://github.com/asyncapi/parser-js/issues/344
Fixes https://github.com/asyncapi/parser-js/issues/504

jonaslagoni avatar Sep 14 '22 11:09 jonaslagoni

:tada: This PR is included in version 1.16.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

asyncapi-bot avatar Sep 14 '22 12:09 asyncapi-bot

@all-contributors please add @aeworxet for code

derberg avatar Sep 15 '22 09:09 derberg

@derberg

I've put up a pull request to add @aeworxet! :tada:

allcontributors[bot] avatar Sep 15 '22 09:09 allcontributors[bot]

:tada: This PR is included in version 2.0.0-next-major.18 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

asyncapi-bot avatar Apr 24 '23 09:04 asyncapi-bot