Skip to content

Commit

Permalink
Use a "no throw" version of decodeURIComponent for text indexing (#4269)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin authored Mar 7, 2024
1 parent 0260065 commit 67d5877
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/text-indexing/src/types/gff3Adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createGunzip } from 'zlib'
import readline from 'readline'
import { Track } from '../util'
import { Track, decodeURIComponentNoThrow } from '../util'
import { getLocalOrRemoteStream } from './common'
import { checkAbortSignal } from '@jbrowse/core/util'

Expand Down Expand Up @@ -51,7 +51,7 @@ export async function* indexGff3(
.map(f => f.split('='))
.map(([key, val]) => [
key.trim(),
decodeURIComponent(val).trim().split(',').join(' '),
decodeURIComponentNoThrow(val).trim().split(',').join(' '),
]),
)
const attrs = attributes
Expand Down
6 changes: 4 additions & 2 deletions packages/text-indexing/src/types/vcfAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createGunzip } from 'zlib'
import readline from 'readline'
import { Track } from '../util'
import { Track, decodeURIComponentNoThrow } from '../util'
import { getLocalOrRemoteStream } from './common'
import { checkAbortSignal } from '@jbrowse/core/util'

Expand Down Expand Up @@ -52,7 +52,9 @@ export async function* indexVcf(
.map(f => f.split('='))
.map(([key, val]) => [
key.trim(),
val ? decodeURIComponent(val).trim().split(',').join(' ') : undefined,
val
? decodeURIComponentNoThrow(val).trim().split(',').join(' ')
: undefined,
]),
)

Expand Down
9 changes: 9 additions & 0 deletions packages/text-indexing/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,12 @@ export function findTrackConfigsToIndex(
)
.filter(track => isSupportedIndexingAdapter(track.adapter?.type))
}

export function decodeURIComponentNoThrow(uri: string) {
try {
return decodeURIComponent(uri)
} catch (e) {
// avoid throwing exception on a failure to decode URI component
return uri
}
}
10 changes: 5 additions & 5 deletions products/jbrowse-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ It is likely preferable in most cases to install the tools globally with
- [`jbrowse add-track-json TRACK`](#jbrowse-add-track-json-track)
- [`jbrowse admin-server`](#jbrowse-admin-server)
- [`jbrowse create LOCALPATH`](#jbrowse-create-localpath)
- [`jbrowse help [COMMANDS]`](#jbrowse-help-commands)
- [`jbrowse help [COMMAND]`](#jbrowse-help-command)
- [`jbrowse make-pif FILE`](#jbrowse-make-pif-file)
- [`jbrowse remove-track TRACK`](#jbrowse-remove-track-track)
- [`jbrowse set-default-session`](#jbrowse-set-default-session)
Expand Down Expand Up @@ -458,16 +458,16 @@ EXAMPLES
_See code:
[src/commands/create.ts](https://github.com/GMOD/jbrowse-components/blob/v2.10.3/products/jbrowse-cli/src/commands/create.ts)_

## `jbrowse help [COMMANDS]`
## `jbrowse help [COMMAND]`

Display help for jbrowse.

```
USAGE
$ jbrowse help [COMMANDS] [-n]
$ jbrowse help [COMMAND] [-n]
ARGUMENTS
COMMANDS Command to show help for.
COMMAND Command to show help for.
FLAGS
-n, --nested-commands Include all nested commands in the output.
Expand All @@ -477,7 +477,7 @@ DESCRIPTION
```

_See code:
[@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.15/src/commands/help.ts)_
[@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.17/src/commands/help.ts)_

## `jbrowse make-pif FILE`

Expand Down
4 changes: 2 additions & 2 deletions products/jbrowse-cli/src/types/gff3Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import readline from 'readline'

// locals
import { Track } from '../base'
import { getLocalOrRemoteStream } from '../util'
import { decodeURIComponentNoThrow, getLocalOrRemoteStream } from '../util'

export async function* indexGff3({
config,
Expand Down Expand Up @@ -75,7 +75,7 @@ export async function* indexGff3({
.map(f => f.split('='))
.map(([key, val]) => [
key.trim(),
decodeURIComponent(val).trim().split(',').join(' '),
decodeURIComponentNoThrow(val).trim().split(',').join(' '),
]),
)
const attrs = attributesToIndex
Expand Down
6 changes: 4 additions & 2 deletions products/jbrowse-cli/src/types/vcfAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import readline from 'readline'

// locals
import { Track } from '../base'
import { getLocalOrRemoteStream } from '../util'
import { decodeURIComponentNoThrow, getLocalOrRemoteStream } from '../util'

export async function* indexVcf({
config,
Expand Down Expand Up @@ -73,7 +73,9 @@ export async function* indexVcf({
.map(f => f.split('='))
.map(([key, val]) => [
key.trim(),
val ? decodeURIComponent(val).trim().split(',').join(' ') : undefined,
val
? decodeURIComponentNoThrow(val).trim().split(',').join(' ')
: undefined,
]),
)

Expand Down
9 changes: 9 additions & 0 deletions products/jbrowse-cli/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ export async function getLocalOrRemoteStream(uri: string, out: string) {
}
return { totalBytes, stream }
}

export function decodeURIComponentNoThrow(uri: string) {
try {
return decodeURIComponent(uri)
} catch (e) {
// avoid throwing exception on a failure to decode URI component
return uri
}
}

0 comments on commit 67d5877

Please sign in to comment.