Giter Site home page Giter Site logo

tjenkinson / url-toolkit Goto Github PK

View Code? Open in Web Editor NEW
30.0 4.0 0.0 1.21 MB

Build an absolute URL from a base URL and a relative URL (RFC 1808).

Home Page: https://tools.ietf.org/html/rfc1808

License: Apache License 2.0

JavaScript 99.73% Shell 0.27%
url urls url-parsing jsdelivr relative-url absolute-url normalize rfc-1808 typescript types

url-toolkit's Introduction

npm version

URL Toolkit

Lightweight library to build an absolute URL from a base URL and a relative URL, written from the spec (RFC 1808). Initially part of HLS.JS.

Differences to JS URL()

The JS URL() function also lets you calculate a new URL from a base and relative one.

That uses the URL Living Standard which is slightly different to RFC 1808 that this library implements.

One of the key differences is that the URL Living Standard has the concept of a 'special url' and 'special scheme'. For these special URL's, such as a URL with the http scheme, they normalise them in a way that results in http:///example.com/something becoming http://example.com/something. This library does not do that and parseURL() would give you // as the netLoc and /example.com as the path.

Methods

buildAbsoluteURL(baseURL, relativeURL, opts={})

Build an absolute URL from a relative and base one.

URLToolkit.buildAbsoluteURL('http://a.com/b/cd', 'e/f/../g'); // => http://a.com/b/e/g

If you want to ensure that the URL is treated as a relative one you should prefix it with ./.

URLToolkit.buildAbsoluteURL('http://a.com/b/cd', 'a:b'); // => a:b
URLToolkit.buildAbsoluteURL('http://a.com/b/cd', './a:b'); // => http://a.com/b/a:b

By default the paths will not be normalized unless necessary, according to the spec. However you can ensure paths are always normalized by setting the opts.alwaysNormalize option to true.

URLToolkit.buildAbsoluteURL('http://a.com/b/cd', '/e/f/../g'); // => http://a.com/e/f/../g
URLToolkit.buildAbsoluteURL('http://a.com/b/cd', '/e/f/../g', {
  alwaysNormalize: true,
}); // => http://a.com/e/g

normalizePath(url)

Normalizes a path.

URLToolkit.normalizePath('a/b/../c'); // => a/c

parseURL(url)

Parse a URL into its separate components.

URLToolkit.parseURL('http://a/b/c/d;p?q#f'); // =>
/* {
	scheme: 'http:',
	netLoc: '//a',
	path: '/b/c/d',
	params: ';p',
	query: '?q',
	fragment: '#f'
} */

buildURLFromParts(parts)

Puts all the parts from parseURL() back together into a string.

Example

var URLToolkit = require('url-toolkit');
var url = URLToolkit.buildAbsoluteURL(
  'https://a.com/b/cd/e.m3u8?test=1#something',
  '../z.ts?abc=1#test'
);
console.log(url); // 'https://a.com/b/z.ts?abc=1#test'

Browser

This can also be used in the browser thanks to jsDelivr:

<head>
  <script
    type="text/javascript"
    src="https://cdn.jsdelivr.net/npm/url-toolkit@2"
  ></script>
  <script type="text/javascript">
    var url = URLToolkit.buildAbsoluteURL(
      'https://a.com/b/cd/e.m3u8?test=1#something',
      '../z.ts?abc=1#test'
    );
    console.log(url); // 'https://a.com/b/z.ts?abc=1#test'
  </script>
</head>

url-toolkit's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar greenkeeper[bot] avatar tjenkinson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

url-toolkit's Issues

Failures on some edge cases and #fragments

Hello

I'm looking for a JS library compatible with this PHP library https://github.com/monkeysuffrage/phpuri and so far this is looking promising. It seems to fail for a fragment/anchor case and some edge cases with periods.

I ran the tests from phpuri on url-toolkit and got 30 passes and 5 failures. The failures were:

URLToolkit.buildAbsoluteURL('http://a/b/c/d;p?q', '#s') should be 'http://a/b/c/d;p?q#s' but results in 'http://a/b/c/#s'
URLToolkit.buildAbsoluteURL('http://a/b/c/d;p?q', '.') should be 'http://a/b/c/' but results in 'http://a/b/c/.'
URLToolkit.buildAbsoluteURL('http://a/b/c/d;p?q', '..') should be 'http://a/b/' but results in 'http://a/b/c/..'
URLToolkit.buildAbsoluteURL('http://a/b/c/d;p?q', '../..') should be 'http://a/' but results in 'http://a/b/..'
URLToolkit.buildAbsoluteURL('http://a/b/c/d;p?q', './g/.') should be 'http://a/b/c/g/' but results in 'http://a/b/c/g/.'

For inputs that are only #fragments they should always be added to the end of the URL, and not replace the query parameter.

Issue building absolute URL with port

I tried to build an absolute URL with the following input

URLToolkit.buildAbsoluteURL("modbus+tcp://192.168.178.123:502/unitid", "/40001?quantity=2");

My assumption was to get the following absolute URL
"modbus+tcp://192.168.178.123:502/unitid/40001?quantity=2"
while getting the following
"modbus+tcp://192.168.178.123:502/40001?quantity=2"

Somehow it seems that after the port 502 nothing is taken into account anymore....

see eclipse-thingweb/node-wot#1139

Trying to get in touch with you regarding a security issue

Hi there,

I couldn't find a SECURITY.md in your repository and so am not sure how to best contact you privately to disclose the security issue.

Can you add a SECURITY.md file with your e-mail to your repository, so that I know who to contact? GitHub suggests that a security policy is the best way to make sure security issues are responsibly disclosed.

Once you've done that, please let me know so I can ping you the info.

Thanks! (cc @JamieSlome)

'Event.path' is deprecated and will be removed in M109, around January 2023. Please use 'Event.composedPath()' instead. See https://www.chromestatus.com/feature/5726124632965120 for more details.

Como resolver o seguinte problema?
Deprecation / Warning
'Event.path' is deprecated and will be removed in M109, around January 2023. Please use 'Event.composedPath()' instead. See https://www.chromestatus.com/feature/5726124632965120 for more details.

Source
https://www.gstatic.com/mysidia/392485333be51ca55ba863b6f3110f01.js?tag=video_mra/web_raspberry

Uma resposta incompleta que achei foi a seguinte
Acesse Status da plataforma Chrome e expanda as entradas das APIs que você está usando para saber por que as APIs estão obsoletas e como substituí-las.
Vocês podem me explicar como resolver esse problema de forma definitiva... Eu preciso do passo a passo....
Dar para resolver esse problema entrando no HTML do site e removendo?
Se agente remover, qual a outra API que colocamos no lugar? ou não precisa?

Se você souber da explicação completa pra resolver esse problema, poste aqui? FIcarei muito grato por sua ajuda!

URLs with un-encoded semicolons do not produce expected result

Semi-colon use in URLs

Aside from dot-segments in hierarchical paths, a path segment is considered opaque by the generic syntax. URI producing applications often use the reserved characters allowed in a segment to delimit scheme-specific or dereference-handler-specific subcomponents. For example, the semicolon (";") and equals ("=") reserved characters are often used to delimit parameters and parameter values applicable to that segment.

source http://www.ietf.org/rfc/rfc3986.txt

Failed Test

test('http://a.com/expiretime=111;dirmatch=true/master.m3u8', './a:b', 'http://a.com/expiretime=111;dirmatch=true/a:b', { alwaysNormalize: true });

Passing Test

test('http://a.com/expiretime=111%3Bdirmatch=true/master.m3u8', './a:b', 'http://a.com/expiretime=111%3Bdirmatch=true/a:b', { alwaysNormalize: true });

In this specific case, it is used as a delimiter for the segment's configuration (tokenization in my case). Though, the web server is accepting both ; and the encoded %3B.

concate ipv6 link failed

e.g.

let baseUrl = 'http://[2001:1:1:1::1]/apple/index.m3u8'; let url = '03.m3u8' let dstUrl = URLToolkit.buildAbsoluteURL(baseUrl, url, { alwaysNormalize: true });
dstUrl: http://[2001:1/:1:1::1]/apple/03.m3u8

Which is wrong.

Could you help to check it?

Obsoleted by: 3986

RFC 1808 is Obsoleted by RFC 3986.

You note in the readme that this project does not use the living standard.
Is it worth also noting that RFC 1808 is now obsolete, and the differences in what this library supports?

[^] in regex may cause an error

I need to use a new version of your library in my legacy project, but the project fails to build because of invalid character in regex: [^]. It was added in two places in this commit.

[\s\S] does the same thing (matches any character including newline), and it is more common. I believe it would fix the error.

Thank you!

An in-range update of mocha is breaking the build 🚨

Version 3.4.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.3.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v3.4.0

Mocha is now moving to a quicker release schedule: when non-breaking changes are merged, a release should happen that week.

This week's highlights:

  • allowUncaught added to commandline as --allow-uncaught (and bugfixed)
  • warning-related Node flags

🎉 Enhancements

🐛 Fixes

🔩 Other

Commits

The new version differs by 9 commits0.

  • 7554b31 Add Changelog for v3.4.0
  • 9f7f7ed Add --trace-warnings flag
  • 92561c8 Add --no-warnings flag
  • ceee976 lint test/integration/fixtures/simple-reporter.js
  • dcfc094 Revert "use semistandard directly"
  • 93392dd no special case for macOS running Karma locally
  • 4d1d91d --allow-uncaught cli option
  • fb1e083 fix allowUncaught in browser
  • 4ed3fc5 Add license report and scan status

false

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

como reduzir javascript no blogspot?

Reduza o JavaScript não utilizado e adie os scripts de carregamento até que sejam necessários para diminuir os bytes consumidos pela atividade da rede.
Vocês conhecem algum código para colocar no html do blogspot que reduz automáticametente os arquivos em javascript?
tem algum código que remove automaticamente os códigos javascripts não utilizados...
Se você sabe a solução desse problema...você pode postar aqui o passo a passo para fazer isso?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.