parseURI separates querystrings
This commit is contained in:
parent
3ebbb4470c
commit
e8c6efcea8
2 changed files with 26 additions and 2 deletions
13
dist/bundle.es.js
vendored
13
dist/bundle.es.js
vendored
|
@ -907,6 +907,8 @@ const regexAddress = /^(b|r)(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/;
|
||||||
const regexPartProtocol = '^((?:lbry://)?)';
|
const regexPartProtocol = '^((?:lbry://)?)';
|
||||||
const regexPartStreamOrChannelName = '([^:$#/]*)';
|
const regexPartStreamOrChannelName = '([^:$#/]*)';
|
||||||
const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
||||||
|
const queryStringBreaker = '^([\\S]+)([?][\\S]*)';
|
||||||
|
const separateQuerystring = new RegExp(queryStringBreaker);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a LBRY name into its component parts. Throws errors with user-friendly
|
* Parses a LBRY name into its component parts. Throws errors with user-friendly
|
||||||
|
@ -927,13 +929,21 @@ const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
||||||
|
|
||||||
function parseURI(URL, requireProto = false) {
|
function parseURI(URL, requireProto = false) {
|
||||||
// Break into components. Empty sub-matches are converted to null
|
// Break into components. Empty sub-matches are converted to null
|
||||||
|
|
||||||
const componentsRegex = new RegExp(regexPartProtocol + // protocol
|
const componentsRegex = new RegExp(regexPartProtocol + // protocol
|
||||||
regexPartStreamOrChannelName + // stream or channel name (stops at the first separator or end)
|
regexPartStreamOrChannelName + // stream or channel name (stops at the first separator or end)
|
||||||
regexPartModifierSeparator + // modifier separator, modifier (stops at the first path separator or end)
|
regexPartModifierSeparator + // modifier separator, modifier (stops at the first path separator or end)
|
||||||
'(/?)' + // path separator, there should only be one (optional) slash to separate the stream and channel parts
|
'(/?)' + // path separator, there should only be one (optional) slash to separate the stream and channel parts
|
||||||
regexPartStreamOrChannelName + regexPartModifierSeparator);
|
regexPartStreamOrChannelName + regexPartModifierSeparator);
|
||||||
|
// chop off the querystring first
|
||||||
|
let QSStrippedURL, qs;
|
||||||
|
const qsRegexResult = separateQuerystring.exec(URL);
|
||||||
|
if (qsRegexResult) {
|
||||||
|
[QSStrippedURL, qs] = qsRegexResult.slice(1).map(match => match || null);
|
||||||
|
}
|
||||||
|
|
||||||
const regexMatch = componentsRegex.exec(URL) || [];
|
const cleanURL = QSStrippedURL || URL;
|
||||||
|
const regexMatch = componentsRegex.exec(cleanURL) || [];
|
||||||
const [proto, ...rest] = regexMatch.slice(1).map(match => match || null);
|
const [proto, ...rest] = regexMatch.slice(1).map(match => match || null);
|
||||||
const path = rest.join('');
|
const path = rest.join('');
|
||||||
const [streamNameOrChannelName, primaryModSeparator, primaryModValue, pathSep, possibleStreamName, secondaryModSeparator, secondaryModValue] = rest;
|
const [streamNameOrChannelName, primaryModSeparator, primaryModValue, pathSep, possibleStreamName, secondaryModSeparator, secondaryModValue] = rest;
|
||||||
|
@ -985,6 +995,7 @@ function parseURIModifier(modSeperator, modValue) {
|
||||||
let claimId;
|
let claimId;
|
||||||
let claimSequence;
|
let claimSequence;
|
||||||
let bidPosition;
|
let bidPosition;
|
||||||
|
|
||||||
if (modSeperator) {
|
if (modSeperator) {
|
||||||
if (!modValue) {
|
if (!modValue) {
|
||||||
throw new Error(__(`No modifier provided after separator %s.`, modSeperator));
|
throw new Error(__(`No modifier provided after separator %s.`, modSeperator));
|
||||||
|
|
|
@ -9,6 +9,10 @@ export const regexAddress = /^(b|r)(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/;
|
||||||
const regexPartProtocol = '^((?:lbry://)?)';
|
const regexPartProtocol = '^((?:lbry://)?)';
|
||||||
const regexPartStreamOrChannelName = '([^:$#/]*)';
|
const regexPartStreamOrChannelName = '([^:$#/]*)';
|
||||||
const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
||||||
|
const queryStringBreaker = '^([\\S]+)([?][\\S]*)';
|
||||||
|
const separateQuerystring = new RegExp(
|
||||||
|
queryStringBreaker
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a LBRY name into its component parts. Throws errors with user-friendly
|
* Parses a LBRY name into its component parts. Throws errors with user-friendly
|
||||||
|
@ -29,6 +33,7 @@ const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
||||||
|
|
||||||
export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj {
|
export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj {
|
||||||
// Break into components. Empty sub-matches are converted to null
|
// Break into components. Empty sub-matches are converted to null
|
||||||
|
|
||||||
const componentsRegex = new RegExp(
|
const componentsRegex = new RegExp(
|
||||||
regexPartProtocol + // protocol
|
regexPartProtocol + // protocol
|
||||||
regexPartStreamOrChannelName + // stream or channel name (stops at the first separator or end)
|
regexPartStreamOrChannelName + // stream or channel name (stops at the first separator or end)
|
||||||
|
@ -37,8 +42,15 @@ export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj
|
||||||
regexPartStreamOrChannelName +
|
regexPartStreamOrChannelName +
|
||||||
regexPartModifierSeparator
|
regexPartModifierSeparator
|
||||||
);
|
);
|
||||||
|
// chop off the querystring first
|
||||||
|
let QSStrippedURL, qs;
|
||||||
|
const qsRegexResult = separateQuerystring.exec(URL)
|
||||||
|
if (qsRegexResult) {
|
||||||
|
[QSStrippedURL, qs] = qsRegexResult.slice(1).map(match => match || null);
|
||||||
|
}
|
||||||
|
|
||||||
const regexMatch = componentsRegex.exec(URL) || [];
|
const cleanURL = QSStrippedURL || URL;
|
||||||
|
const regexMatch = componentsRegex.exec(cleanURL) || [];
|
||||||
const [proto, ...rest] = regexMatch.slice(1).map(match => match || null);
|
const [proto, ...rest] = regexMatch.slice(1).map(match => match || null);
|
||||||
const path = rest.join('');
|
const path = rest.join('');
|
||||||
const [
|
const [
|
||||||
|
@ -114,6 +126,7 @@ function parseURIModifier(modSeperator: ?string, modValue: ?string) {
|
||||||
let claimId;
|
let claimId;
|
||||||
let claimSequence;
|
let claimSequence;
|
||||||
let bidPosition;
|
let bidPosition;
|
||||||
|
|
||||||
if (modSeperator) {
|
if (modSeperator) {
|
||||||
if (!modValue) {
|
if (!modValue) {
|
||||||
throw new Error(__(`No modifier provided after separator %s.`, modSeperator));
|
throw new Error(__(`No modifier provided after separator %s.`, modSeperator));
|
||||||
|
|
Loading…
Reference in a new issue