How to handle the escape sequence for the % character in encodeURI using JavaScript

Currently, I am facing an issue where I must maintain the presence of %2F in a URI string. Unfortunately, when using encodeURI, the % sign gets encoded as %25 (which is normal), causing the entire string to become %252F instead of %2F. How can I prevent this from happening and ensure that the % doesn't get encoded? The situation is complex as it occurs deep within a framework, ruling out JavaScript manipulation as a solution - the only option is to handle it through string escaping methods. Despite trying various approaches involving backslashes (\), none have proven successful so far.

Answer №1

To maintain control while decoding, consider using the unescape() function prior to decodeURI. By doing this, double encoding issues can be consistently resolved.

For instance:

decodeURIComponent(unescape("http%253A%252F%252Fabcd.com"));

will yield

'http://abcd.com'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Capturing keyboard input in fullscreen mode does not appear to be functioning

I am currently developing a game using Three.js and I am in need of capturing user input. I have two handler functions set up for this purpose; function press(evt) { console.log(evt); var code = evt.which || evt.keyCode; switch(code) { ...

Employing a lexicon of hexadecimal color code values to harmonize CSS styles

I have a unique requirement where I need to utilize a dictionary of HTML color codes and then apply those colors as styles. It's an interesting challenge! Here is an example of how my color dictionary looks like: const colorCodes = { red: ...

Learn how to send messages to specific clients by using the property names of a JavaScript object

In my code, I have an object called var usernames = {}; When the client logs in, they emit addUser to the server. socket.on('addUser', function(data) { if (usernames[data] == undefined) { socket.username = data; username = ...

Oops! An error occurred in AngularJs: "TypeError: $scope.todos.push is not a

I am currently facing an issue while using the $http.get method to add a todo from my controller to my database. The error message "TypeError: $scope.todos.push is not a function" keeps appearing, despite trying various solutions suggested by similar quest ...

Creating Docker images in a lerna monorepo without the need for publishing

In the context of Lerna monorepos, the primary goal is to facilitate branch building and deployments. The challenge arises from the fact that Lerna monorepos either consolidate dependencies in NPM or utilize yarn workspaces to achieve the same outcome, re ...

`Misconceptions in understanding AngularJS directives`

I am currently working on a new app that includes both a header and main view, utilizing directives. At first, I had the directive in its own file but decided to relocate it into app.js in order to resolve an issue. Throughout this process, I have experim ...

Dynamic CSS manipulation with jQuery: Generate and access styles on the fly

I am working on an application where I am utilizing jQuery along with maphilight for highlighting image map segments. In addition to this functionality, I want to dynamically highlight specific HTML elements based on mouseover/mouseout events for the image ...

Bring together a set of elements within a collection of identical entities that contain corresponding key-value pairs by utilizing JavaScript

Looking at the object below: a = [ {id: 1, comp: 'ans', stat: 'www', value: ['1', '2']}, {id: 2, comp: 'qsn', stat: 'xxx', value: ['a', 'b']}, {id: 3, comp: 'ans', ...

Node and Web scraping Promise: a powerful combination

I've been using Cheerio and Node for web scraping, and I thought implementing promises could simplify handling asynchronous code. However, my attempt to chain promises hasn't been successful. Below is the code I'm working with, in hopes that ...

Transform the MUI Typescript Autocomplete component to output singular values of a specific property rather than a complete object

When utilizing MUI Autocomplete, the generic value specified in onChange / value is determined by the interface of the object set in the options property. For instance, consider an autocomplete with the following setup: <Autocomplete options={top ...

Warning: Trying to access an undefined property within an async function in Typescript

Recently, I have been tackling an issue with my API that is built with TypeScript and NodeJS. The problem arises when my Promises seem to not resolve correctly in the following code snippet: async function retrieveData() { return new Promise((reso ...

What is the procedure for populating a listbox with items selected from an array?

On my aspx page, there is a listbox (techGroups) with preselected items that users can change. I also have a reset button that should restore the listbox to its original selections when clicked. However, I am encountering an issue where only the first pres ...

Exploring the AngularJS functionality of AngularForEach within nested arrays

I've just started diving into AngularJS and I'm facing some challenges with using angular.forEach... Specifically, I have a data object retrieved from my REST API... My goal is to iterate through a nested array, look for a specific attribute, an ...

Digits disappearing beyond the screen in a JavaScript calculator

I'm currently working on a small calculator project and encountering an issue where the input numbers continue to fill the display even when it's already full. I'd like to limit the input once the display reaches its maximum capacity. If yo ...

The attribute 'tableName' is not found within the 'Model' type

Currently in the process of converting a JavaScript code to TypeScript. Previously, I had a class that was functioning correctly in JS class Model { constructor(input, alias) { this.tableName = input; this.alias = alias; } } Howev ...

Material UI (4.9.2) in React Js (16.8.5) with a nested menu functionality

I have been working on creating a nested menu using Material UI, without relying on any third-party packages. Progress So Far: Successfully created a menu along with menu items. Added a button to one of the menu items. Implemented functionality to open an ...

Discovering objects in Javascript: A comprehensive guide

I am working with a data object that looks like this: var elements = { 'element' : { 'name' : 'test', 'price' : '55' }, 'element' : { ...

Switching CSS Unicode to JavaScript

I've been using a few emoji unicodes that work great in CSS: content: "\f410" content: "\f2d1" I attempted to display them with JavaScript, but unfortunately, I was unsuccessful. Any suggestions you have would be ...

Issue with jQuery function not recognizing escaped double quotes in PHP script

Greetings! I am currently utilizing a custom control with PHP code. $parentLinkCombo = '<select name="ParentComboLink" onchange="changeChildCombo(\"LICENCE\");" id="ParentComboLink" >'; In order to handle the onchange event, I ...

When using jQuery, the function $(this).serialize() will not include input fields that have

Is there a way to serialize and send an entire form using jQuery post, even if only some items have been changed? I want all form fields to be included in the serialization. Here's my HTML: <form name ="XXX" class="user_goal_form"> <input ...