# tryDecodeURI

**Kind:** Function

**Source:** [`src/utils/url.ts`](https://github.com/honojs/hono/blob/main/src/utils/url.ts#L104)

**Part of:** [Utils](subsystem-src-utils)

Try to apply decodeURI() to given string.
If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.

`tryDecodeURI` attempts to decode a URI string with `decodeURI()`. If decoding fails because the input contains invalid percent encoding or invalid UTF-8 sequences, it skips the invalid data and decodes the remaining portions where possible.

## Signature

```ts
function tryDecodeURI(str: string): string
```

## Parameters

| Name | Type |
|---|---|
| `str` | `string` |

**Returns:** `string`

## Diagram

```mermaid
graph LR
  Input[URI string] --> Decode[Attempt decodeURI]
  Decode -->|Success| Result[Return decoded string]
  Decode -->|Failure| Recover[Skip invalid encoding data]
  Recover --> Partial[Decode remaining portions]
  Partial --> Result
```

## Usage

```ts
import { tryDecodeURI } from './utils/url';

const value = 'https://example.com/search?q=hello%20world%ZZ';

const decoded = tryDecodeURI(value);

console.log(decoded);
// https://example.com/search?q=hello world%ZZ
```

## AI Coding Instructions

- Keep this helper focused on tolerant URI decoding behavior.
- Use `decodeURI()` rather than `decodeURIComponent()` so URI delimiters retain their expected handling.
- Do not throw when malformed percent encoding or invalid UTF-8 data is present.
- Preserve undecodable input data while decoding portions that can be decoded.

## Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Imported by (1)

- `ServeStaticOptions` — `src/middleware/serve-static/index.ts`:13
