Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash on badly encoded GFF attributes #4269

Merged
merged 2 commits into from Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/text-indexing/src/types/gff3Adapter.ts
@@ -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
@@ -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
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
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
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
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
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
}
}