Merge pull request #191 from lbryio/urlQueryStringsRB
parses querystrings from urls
This commit is contained in:
commit
314e878b34
2 changed files with 28 additions and 3 deletions
15
dist/bundle.es.js
vendored
15
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 regexPartStreamOrChannelName = '([^:$#/]*)';
|
||||
const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
||||
const queryStringBreaker = '^([\\S]+)([?][\\S]*)';
|
||||
const separateQuerystring = new RegExp(queryStringBreaker);
|
||||
|
||||
/**
|
||||
* Parses a LBRY name into its component parts. Throws errors with user-friendly
|
||||
|
@ -927,13 +929,21 @@ const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
|||
|
||||
function parseURI(URL, requireProto = false) {
|
||||
// Break into components. Empty sub-matches are converted to null
|
||||
|
||||
const componentsRegex = new RegExp(regexPartProtocol + // protocol
|
||||
regexPartStreamOrChannelName + // stream or channel name (stops at the first 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
|
||||
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 path = rest.join('');
|
||||
const [streamNameOrChannelName, primaryModSeparator, primaryModValue, pathSep, possibleStreamName, secondaryModSeparator, secondaryModValue] = rest;
|
||||
|
@ -978,13 +988,14 @@ function parseURI(URL, requireProto = false) {
|
|||
// They will not work properly with canonical_urls
|
||||
claimName: streamNameOrChannelName,
|
||||
claimId: primaryClaimId
|
||||
}, streamName ? { contentName: streamName } : {});
|
||||
}, streamName ? { contentName: streamName } : {}, qs ? { queryString: qs } : {});
|
||||
}
|
||||
|
||||
function parseURIModifier(modSeperator, modValue) {
|
||||
let claimId;
|
||||
let claimSequence;
|
||||
let bidPosition;
|
||||
|
||||
if (modSeperator) {
|
||||
if (!modValue) {
|
||||
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 regexPartStreamOrChannelName = '([^:$#/]*)';
|
||||
const regexPartModifierSeparator = '([:$#]?)([^/]*)';
|
||||
const queryStringBreaker = '^([\\S]+)([?][\\S]*)';
|
||||
const separateQuerystring = new RegExp(
|
||||
queryStringBreaker
|
||||
);
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
// Break into components. Empty sub-matches are converted to null
|
||||
|
||||
const componentsRegex = new RegExp(
|
||||
regexPartProtocol + // protocol
|
||||
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 +
|
||||
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 path = rest.join('');
|
||||
const [
|
||||
|
@ -107,6 +119,7 @@ export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj
|
|||
claimName: streamNameOrChannelName,
|
||||
claimId: primaryClaimId,
|
||||
...(streamName ? { contentName: streamName } : {}),
|
||||
...(qs ? { queryString: qs} : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -114,6 +127,7 @@ function parseURIModifier(modSeperator: ?string, modValue: ?string) {
|
|||
let claimId;
|
||||
let claimSequence;
|
||||
let bidPosition;
|
||||
|
||||
if (modSeperator) {
|
||||
if (!modValue) {
|
||||
throw new Error(__(`No modifier provided after separator %s.`, modSeperator));
|
||||
|
|
Loading…
Add table
Reference in a new issue