Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #39241 > unrolled thread
| Started by | JRough <janis.rough@gmail.com> |
|---|---|
| First post | 2020-12-07 07:54 -0800 |
| Last post | 2020-12-07 09:53 -0800 |
| Articles | 10 — 4 participants |
Back to article view | Back to comp.lang.javascript
string function doesn't have array functions JRough <janis.rough@gmail.com> - 2020-12-07 07:54 -0800
Re: string function doesn't have array functions Julio Di Egidio <julio@diegidio.name> - 2020-12-07 08:30 -0800
Re: string function doesn't have array functions JRough <janis.rough@gmail.com> - 2020-12-07 09:15 -0800
Re: string function doesn't have array functions "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-12-07 10:06 -0800
Re: string function doesn't have array functions JRough <janis.rough@gmail.com> - 2020-12-07 10:28 -0800
Re: string function doesn't have array functions "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-12-07 11:33 -0800
Re: string function doesn't have array functions Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-12-07 23:35 +0100
Re: string function doesn't have array functions "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-12-07 14:36 -0800
Re: string function doesn't have array functions JRough <janis.rough@gmail.com> - 2020-12-07 15:29 -0800
Re: string function doesn't have array functions "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-12-07 09:53 -0800
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2020-12-07 07:54 -0800 |
| Subject | string function doesn't have array functions |
| Message-ID | <6cf898b5-74a5-43fa-b382-e765287d65d2n@googlegroups.com> |
In headers the xsrf token is getting corrupted so I need to hard code the xsrf token till its fixed. My script works to split the key and the value, but can't write over the old generated token value with the new hard coded value back in the result array. The output array is the same as the input string ???Do you have any ideas?
let cookieData = 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF-TOKEN=D9CF17822CDCA3D8337DE8F4485EA912';
function writeCookie(cookieData){
var cd= [];
cd = cookieData.split(";");
var kvPairs;
var result =[];
for(kvPairs of cd){
let kv = [];
kv = kvPairs.split("=");
let key = kv[0];
let value = kv[1];
console.log("key :" + key);
console.log("value:" + value);
if(key ===('XSRF-Token')){
value = '000123456';
}
result = result + key +"=" +value +";";
}
console.log("The result is:"+ result);
}
writeCookie(cookieData);
[toc] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-12-07 08:30 -0800 |
| Message-ID | <9c34e490-04fd-49a5-8ab5-ff2ba9f0684en@googlegroups.com> |
| In reply to | #39241 |
On Monday, 7 December 2020 at 16:54:43 UTC+1, JRough wrote:
> In headers the xsrf token is getting corrupted so I need to hard code the xsrf token till its fixed. My script works to split the key and the value, but can't write over the old generated token value with the new hard coded value back in the result array. The output array is the same as the input string ???Do you have any ideas?
> let cookieData = 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF-TOKEN=D9CF17822CDCA3D8337DE8F4485EA912';
> function writeCookie(cookieData){
> var cd= [];
> cd = cookieData.split(";");
> var kvPairs;
> var result =[];
>
> for(kvPairs of cd){
> let kv = [];
> kv = kvPairs.split("=");
> let key = kv[0];
> let value = kv[1];
> console.log("key :" + key);
> console.log("value:" + value);
> if(key ===('XSRF-Token')){
> value = '000123456';
> }
> result = result + key +"=" +value +";";
>
> }
> console.log("The result is:"+ result);
> }
> writeCookie(cookieData);
'XSRF-TOKEN' is not equal to 'XSRF-Token'...
Julio
[toc] | [prev] | [next] | [standalone]
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2020-12-07 09:15 -0800 |
| Message-ID | <435c57e1-7ae0-4506-8d38-8560bca6f2dan@googlegroups.com> |
| In reply to | #39242 |
On Monday, December 7, 2020 at 8:30:14 AM UTC-8, ju...@diegidio.name wrote:
> On Monday, 7 December 2020 at 16:54:43 UTC+1, JRough wrote:
> > In headers the xsrf token is getting corrupted so I need to hard code the xsrf token till its fixed. My script works to split the key and the value, but can't write over the old generated token value with the new hard coded value back in the result array. The output array is the same as the input string ???Do you have any ideas?
> > let cookieData = 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF-TOKEN=D9CF17822CDCA3D8337DE8F4485EA912';
> > function writeCookie(cookieData){
> > var cd= [];
> > cd = cookieData.split(";");
> > var kvPairs;
> > var result =[];
> >
> > for(kvPairs of cd){
> > let kv = [];
> > kv = kvPairs.split("=");
> > let key = kv[0];
> > let value = kv[1];
> > console.log("key :" + key);
> > console.log("value:" + value);
> > if(key ===('XSRF-Token')){
> > value = '000123456';
> > }
> > result = result + key +"=" +value +";";
> >
> > }
> > console.log("The result is:"+ result);
> > }
> > writeCookie(cookieData);
> 'XSRF-TOKEN' is not equal to 'XSRF-Token'...
>
> Julio
sorry, that was a typo since I had to copy it from another laptop to my personal laptop to post. I had it right on the other laptop. It is the same result. It doesn't change the array value. I fixed the typo here below but can you tell me how to fix the code?
let cookieData = 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF-TOKEN=D9CF17822CDCA3D8337DE8F4485EA912';
function writeCookie(cookieData){
var cd= [];
cd = cookieData.split(";");
var kvPairs;
var result =[];
for(kvPairs of cd){
let kv = [];
kv = kvPairs.split("=");
let key = kv[0];
let value = kv[1];
console.log("key :" + key);
console.log("value:" + value);
if(key ===('XSRF-TOKEN=')){
value = '000123456';
}
result = result + key +"=" +value +";";
}
console.log("The result is:"+ result);
}
writeCookie(cookieData);
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-12-07 10:06 -0800 |
| Message-ID | <0fdd8034-346a-420a-acaa-ae832f2a88acn@googlegroups.com> |
| In reply to | #39243 |
On Monday, December 7, 2020 at 11:15:59 AM UTC-6, JRough wrote: > sorry, that was a typo since I had to copy it from another laptop to my personal laptop to post. I had it right on the other laptop. It is the same result. It doesn't change the array value. I fixed the typo here below but can you tell me how to fix the code? Perhaps the following library would help? <https://gist.github.com/mlhaufe/01cc0d183774b3444f89447004fd9607>
[toc] | [prev] | [next] | [standalone]
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2020-12-07 10:28 -0800 |
| Message-ID | <e0fc4d1f-6294-40c1-81f8-d9753c383a47n@googlegroups.com> |
| In reply to | #39245 |
On Monday, December 7, 2020 at 10:06:43 AM UTC-8, Michael Haufe (TNO) wrote: > On Monday, December 7, 2020 at 11:15:59 AM UTC-6, JRough wrote: > > > sorry, that was a typo since I had to copy it from another laptop to my personal laptop to post. I had it right on the other laptop. It is the same result. It doesn't change the array value. I fixed the typo here below but can you tell me how to fix the code? > Perhaps the following library would help? > > <https://gist.github.com/mlhaufe/01cc0d183774b3444f89447004fd9607> Well it is HTTPS, and it does have to return as a string. I am not generating the token. It's a nodejs server running express which has a cookie parse utility but this is an old angular.js app. So is there a quick fix or should I use string.replace. I tried that and its harder.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-12-07 11:33 -0800 |
| Message-ID | <41bac879-f5a8-4099-88ff-f8003fbc1de5n@googlegroups.com> |
| In reply to | #39246 |
On Monday, December 7, 2020 at 12:28:18 PM UTC-6, JRough wrote:
> On Monday, December 7, 2020 at 10:06:43 AM UTC-8, Michael Haufe (TNO) wrote:
> > On Monday, December 7, 2020 at 11:15:59 AM UTC-6, JRough wrote:
> >
> > > sorry, that was a typo since I had to copy it from another laptop to my personal laptop to post. I had it right on the other laptop. It is the same result. It doesn't change the array value. I fixed the typo here below but can you tell me how to fix the code?
> > Perhaps the following library would help?
> >
> > <https://gist.github.com/mlhaufe/01cc0d183774b3444f89447004fd9607>
> Well it is HTTPS, and it does have to return as a string. I am not generating the token. It's a nodejs server running express which has a cookie parse utility but this is an old angular.js app. So is there a quick fix or should I use string.replace. I tried that and its harder.
If you already have the full string replacing it is straightforward enough:
```
let cookieData = 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF-TOKEN=D9CF17822CDCA3D8337DE8F4485EA912';
cookieData = cookieData.replace(/XSRF-TOKEN=(.+)\b/,($0,$1) => `XSRF-TOKEN=000123456`)
```
My point with the MDN link was to point out the HttpOnly attribute. If that is set then JavaScript can not access the cookie from the client.
Using the gist I referenced I suspect that the following would be the approach:
```
cookieManager.removeItem('XSRF-TOKEN')
cookieManager.setItem('XSRF-TOKEN', '000123456')
```
Are you doing something exceptional in your case?
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2020-12-07 23:35 +0100 |
| Message-ID | <4278291.LvFx2qVVIh@PointedEars.de> |
| In reply to | #39249 |
Michael Haufe (TNO) wrote:
> If you already have the full string replacing it is straightforward
> enough:
>
> ```
> let cookieData =
> 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF-
^ ^
> TOKEN=D9CF17822CDCA3D8337DE8F4485EA912';
> cookieData = cookieData.replace(/XSRF-TOKEN=(.+)\b/,($0,$1) =>
> `XSRF-TOKEN=000123456`) ```
This replacement will, in general, *obviously* NOT work as expected, as
cookies’ key–value pairs are separated by semicolon, and .+ is greedy.
And there is no need for capturing the old value or for the callback here.
Use .replace(/((?:^|;\s*)XSRF-TOKEN)=[^;]+/, "$1=000123456") instead.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-12-07 14:36 -0800 |
| Message-ID | <1612bbac-65e0-49ed-8a8a-c3155ec15e5an@googlegroups.com> |
| In reply to | #39253 |
On Monday, December 7, 2020 at 4:35:15 PM UTC-6, Thomas 'PointedEars' Lahn wrote: > Michael Haufe (TNO) wrote: > > > If you already have the full string replacing it is straightforward > > enough: > > > > ``` > > let cookieData = > > 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF- > ^ ^ > > TOKEN=D9CF17822CDCA3D8337DE8F4485EA912'; > > cookieData = cookieData.replace(/XSRF-TOKEN=(.+)\b/,($0,$1) => > > `XSRF-TOKEN=000123456`) ``` > This replacement will, in general, *obviously* NOT work as expected, as > cookies’ key–value pairs are separated by semicolon, and .+ is greedy. > And there is no need for capturing the old value or for the callback here. > > Use .replace(/((?:^|;\s*)XSRF-TOKEN)=[^;]+/, "$1=000123456") instead. > Indeed. I'm still fuzzy to the context of the OP's problem.
[toc] | [prev] | [next] | [standalone]
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2020-12-07 15:29 -0800 |
| Message-ID | <e53d8077-e1ad-4e24-a703-7393bc4e4679n@googlegroups.com> |
| In reply to | #39253 |
On Monday, December 7, 2020 at 2:35:15 PM UTC-8, Thomas 'PointedEars' Lahn wrote: > Michael Haufe (TNO) wrote: > > > If you already have the full string replacing it is straightforward > > enough: > > > > ``` > > let cookieData = > > 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF- > ^ ^ > > TOKEN=D9CF17822CDCA3D8337DE8F4485EA912'; > > cookieData = cookieData.replace(/XSRF-TOKEN=(.+)\b/,($0,$1) => > > `XSRF-TOKEN=000123456`) ``` > This replacement will, in general, *obviously* NOT work as expected, as > cookies’ key–value pairs are separated by semicolon, and .+ is greedy. > And there is no need for capturing the old value or for the callback here. > > Use .replace(/((?:^|;\s*)XSRF-TOKEN)=[^;]+/, "$1=000123456") instead. > > -- > PointedEars > FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> > <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> > Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail. very awesome Regex. thanks,
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-12-07 09:53 -0800 |
| Message-ID | <5c7efa41-9a61-497b-9057-199fa911942dn@googlegroups.com> |
| In reply to | #39241 |
On Monday, December 7, 2020 at 9:54:43 AM UTC-6, JRough wrote:
> In headers the xsrf token is getting corrupted so I need to hard code the xsrf token till its fixed. My script works to split the key and the value, but can't write over the old generated token value with the new hard coded value back in the result array. The output array is the same as the input string ???Do you have any ideas?
> let cookieData = 'SSOD-SAT=AFX1AAAAYABvr;s_cc=true;TLTSID=F4FAF40;XSRF-TOKEN=D9CF17822CDCA3D8337DE8F4485EA912';
> function writeCookie(cookieData){
> var cd= [];
> cd = cookieData.split(";");
> var kvPairs;
> var result =[];
>
> for(kvPairs of cd){
> let kv = [];
> kv = kvPairs.split("=");
> let key = kv[0];
> let value = kv[1];
> console.log("key :" + key);
> console.log("value:" + value);
> if(key ===('XSRF-Token')){
> value = '000123456';
> }
> result = result + key +"=" +value +";";
>
> }
> console.log("The result is:"+ result);
> }
> writeCookie(cookieData);
Is `result` supposed to be an array or a string? You're using both.
Also, are your cookies restricted with HttpOnly?
<https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Restrict_access_to_cookies>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web