Anonymous_User Absent Member.
Absent Member.
710 views

Re: safesplit

On 03/16/2015 03:29 PM, Norbert Klasen wrote:
> Hi,
>
> % i = 'c: " a.gif"'.safesplit(' ','"').length;
> 2
> % i = 'c:\\ " a.gif"'.safesplit(' ','"').length;
> 1
>
> Shouldn't both return an array of length 2?


One form of the safesplit method is available here:

https://www.novell.com/developer/plugin-sdk/ref/api/6.1/symbols/src/content_dev_sdk_6.1_common_utils.js.html

While the current method is actually implemented in Java, I presume the
logic is the same.

A '\' is an escape, and since you have it in there twice the first escapes
the second to at least get the backslash into the string. safesplit,
then, sees that as an escape of the next character, a space, which is your
delimiter between tokens.

The following two options seem to work, where "work" means split into two
tokens, though I'm a little curious how this ugly path came to be in the
first place:


'"c:\\ " " a.gif"'.safesplit(' ','"')
'c:\\\\ " a.gif"'.safesplit(' ','"')[0]


Of course the right thing to do is to first fix the incorrect use of
escapes (backslashes):


'c:\\ " a.gif"'.replace('\\','/').safesplit(' ', '"')


--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
3 Replies
Anonymous_User Absent Member.
Absent Member.

Re: safesplit

>>> On 16.03.2015 at 23:14, ab<ab@no-mx.forums.novell.com> wrote:
> On 03/16/2015 03:29 PM, Norbert Klasen wrote:
> > Hi,
> >
> > % i = 'c: " a.gif"'.safesplit(' ','"').length;
> > 2
> > % i = 'c:\\ " a.gif"'.safesplit(' ','"').length;
> > 1
> >
> > Shouldn't both return an array of length 2?

>
> One form of the safesplit method is available here:
>
>

https://www.novell.com/developer/plugin‑sdk/ref/api/6.1/symbols/src/conte

> nt_dev_sdk_6.1_common_utils.js.html
>
> While the current method is actually implemented in Java, I presume the
> logic is the same.
>
> A '\' is an escape, and since you have it in there twice the first
> escapes
> the second to at least get the backslash into the string. safesplit,
> then, sees that as an escape of the next character, a space, which is
> your
> delimiter between tokens.


The backslash is in there twice as this is required to for representing a
backslash in a JavaScript string literal. The actual data is ...backslash
space quote space...

The description says, safesplit "will de-escape embedded quotes; otherwise
it will leave quotes and escapes intact". But actually it de-escapes
delimiters as well and in this misses the beginning of a new token.

Norbert





>>> On 16.03.2015 at 23:14, ab<ab@no-mx.forums.novell.com> wrote:

> On 03/16/2015 03:29 PM, Norbert Klasen wrote:
> > Hi,
> >
> > % i = 'c: " a.gif"'.safesplit(' ','"').length;
> > 2
> > % i = 'c:\\ " a.gif"'.safesplit(' ','"').length;
> > 1
> >
> > Shouldn't both return an array of length 2?

>
> One form of the safesplit method is available here:
>
>

https://www.novell.com/developer/plugin‑sdk/ref/api/6.1/symbols/src/conte

> nt_dev_sdk_6.1_common_utils.js.html
>
> While the current method is actually implemented in Java, I presume the
> logic is the same.
>
> A '\' is an escape, and since you have it in there twice the first
> escapes
> the second to at least get the backslash into the string. safesplit,
> then, sees that as an escape of the next character, a space, which is
> your
> delimiter between tokens.
>
> The following two options seem to work, where "work" means split into
> two
> tokens, though I'm a little curious how this ugly path came to be in the
> first place:
>
>

> '"c:\\ " " a.gif"'.safesplit(' ','"')
> 'c:\\\\ " a.gif"'.safesplit(' ','"')[0]
>

>
> Of course the right thing to do is to first fix the incorrect use of
> escapes (backslashes):
>
>

> 'c:\\ " a.gif"'.replace('\\','/').safesplit(' ', '"')
>


0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: safesplit


Norbert Klasen;255453 Wrote:
> >>> On 16.03.2015 at 23:14, ab<ab@no-mx.forums.novell.com> wrote:

> > On 03/16/2015 03:29 PM, Norbert Klasen wrote:
> > > Hi,
> > >
> > > % i = 'c: " a.gif"'.safesplit(' ','"').length;
> > > 2
> > > % i = 'c:\\ " a.gif"'.safesplit(' ','"').length;
> > > 1
> > >
> > > Shouldn't both return an array of length 2?

> >
> > One form of the safesplit method is available here:
> >
> >

> http://tinyurl.com/p9gf2ul
>
> > nt_dev_sdk_6.1_common_utils.js.html
> >
> > While the current method is actually implemented in Java, I presume

> the
> > logic is the same.
> >
> > A '\' is an escape, and since you have it in there twice the first
> > escapes
> > the second to at least get the backslash into the string. safesplit,
> > then, sees that as an escape of the next character, a space, which is
> > your
> > delimiter between tokens.

>
> The backslash is in there twice as this is required to for representing
> a
> backslash in a JavaScript string literal. The actual data is
> ...backslash
> space quote space...
>
> The description says, safesplit "will de-escape embedded quotes;
> otherwise
> it will leave quotes and escapes intact". But actually it de-escapes
> delimiters as well and in this misses the beginning of a new token.
>
> Norbert
>
>
>
>
>
> >>> On 16.03.2015 at 23:14, ab<ab@no-mx.forums.novell.com> wrote:

> > On 03/16/2015 03:29 PM, Norbert Klasen wrote:
> > > Hi,
> > >
> > > % i = 'c: " a.gif"'.safesplit(' ','"').length;
> > > 2
> > > % i = 'c:\\ " a.gif"'.safesplit(' ','"').length;
> > > 1
> > >
> > > Shouldn't both return an array of length 2?

> >
> > One form of the safesplit method is available here:
> >
> >

> http://tinyurl.com/p9gf2ul
>
> > nt_dev_sdk_6.1_common_utils.js.html
> >
> > While the current method is actually implemented in Java, I presume

> the
> > logic is the same.
> >
> > A '\' is an escape, and since you have it in there twice the first
> > escapes
> > the second to at least get the backslash into the string. safesplit,
> > then, sees that as an escape of the next character, a space, which is
> > your
> > delimiter between tokens.
> >
> > The following two options seem to work, where "work" means split into
> > two
> > tokens, though I'm a little curious how this ugly path came to be in

> the
> > first place:
> >
> > >

Code:
--------------------
> >
> > '"c:\\ " " a.gif"'.safesplit(' ','"')
> > 'c:\\\\ " a.gif"'.safesplit(' ','"')[0]
> >

--------------------
> >
> >
> > Of course the right thing to do is to first fix the incorrect use

> of
> > escapes (backslashes):
> >
> > >

Code:
--------------------
> >
> > 'c:\\ " a.gif"'.replace('\\','/').safesplit(' ', '"')
> >

--------------------
> >


That seems buggy - have you opened a bug on this?


--
brandon.langley
------------------------------------------------------------------------
brandon.langley's Profile: https://forums.netiq.com/member.php?userid=350
View this thread: https://forums.netiq.com/showthread.php?t=53130

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: safesplit

Bug 922925 - safesplit incorrectly parses strings where a token ends with a
backslash


>>> On 19.03.2015 at 13:18,

brandon.langley<brandon.langley@no-mx.forums.netiq.com> wrote:

> Norbert Klasen;255453 Wrote:
> > >>> On 16.03.2015 at 23:14, ab<ab@no‑mx.forums.novell.com> wrote:
> > > On 03/16/2015 03:29 PM, Norbert Klasen wrote:
> > > > Hi,
> > > >
> > > > % i = 'c: " a.gif"'.safesplit(' ','"').length;
> > > > 2
> > > > % i = 'c:\\ " a.gif"'.safesplit(' ','"').length;
> > > > 1
> > > >
> > > > Shouldn't both return an array of length 2?
> > >
> > > One form of the safesplit method is available here:
> > >
> > >

> > http://tinyurl.com/p9gf2ul
> >
> > > nt_dev_sdk_6.1_common_utils.js.html
> > >
> > > While the current method is actually implemented in Java, I presume

> > the
> > > logic is the same.
> > >
> > > A '\' is an escape, and since you have it in there twice the first
> > > escapes
> > > the second to at least get the backslash into the string. safesplit,


> > > then, sees that as an escape of the next character, a space, which is


> > > your
> > > delimiter between tokens.

> >
> > The backslash is in there twice as this is required to for representing


> > a
> > backslash in a JavaScript string literal. The actual data is
> > ...backslash
> > space quote space...
> >
> > The description says, safesplit "will de‑escape embedded quotes;
> > otherwise
> > it will leave quotes and escapes intact". But actually it de‑escapes
> > delimiters as well and in this misses the beginning of a new token.
> >
> > Norbert
> >
> >
> >
> >
> >
> > >>> On 16.03.2015 at 23:14, ab<ab@no‑mx.forums.novell.com> wrote:
> > > On 03/16/2015 03:29 PM, Norbert Klasen wrote:
> > > > Hi,
> > > >
> > > > % i = 'c: " a.gif"'.safesplit(' ','"').length;
> > > > 2
> > > > % i = 'c:\\ " a.gif"'.safesplit(' ','"').length;
> > > > 1
> > > >
> > > > Shouldn't both return an array of length 2?
> > >
> > > One form of the safesplit method is available here:
> > >
> > >

> > http://tinyurl.com/p9gf2ul
> >
> > > nt_dev_sdk_6.1_common_utils.js.html
> > >
> > > While the current method is actually implemented in Java, I presume

> > the
> > > logic is the same.
> > >
> > > A '\' is an escape, and since you have it in there twice the first
> > > escapes
> > > the second to at least get the backslash into the string. safesplit,


> > > then, sees that as an escape of the next character, a space, which is


> > > your
> > > delimiter between tokens.
> > >
> > > The following two options seem to work, where "work" means split into


> > > two
> > > tokens, though I'm a little curious how this ugly path came to be in

> > the
> > > first place:
> > >
> > > >

> Code:
> ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
> > >
> > > '"c:\\ " " a.gif"'.safesplit(' ','"')
> > > 'c:\\\\ " a.gif"'.safesplit(' ','"')[0]
> > >

> ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
> > >
> > >
> > > Of course the right thing to do is to first fix the incorrect use

> > of
> > > escapes (backslashes):
> > >
> > > >

> Code:
> ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
> > >
> > > 'c:\\ " a.gif"'.replace('\\','/').safesplit(' ', '"')
> > >

> ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
> > >

>
> That seems buggy ‑ have you opened a bug on this?
>







0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.