[Ext] Re: Scripted Attribute / weird issue

Brent Putman putmanb at georgetown.edu
Sat Jul 30 14:04:59 EDT 2016



On 7/29/16 4:51 PM, Bryan Wooten wrote:
>
>
> I tried all kinds of escape syntax, none worked on any javascript
> strings.

Actually, that's a good point.  I think at that point in the script
that value is indeed a Javascript string, not an instance of the Java
String class.  So that might change the diagnosis and solution. I'm not
a Javascript expert. However, I tried basically what you're doing in my
browser's console and it seems to work as expected:

console.log("[[Summer 2016$7981$EAS$1060$001$LEC$Expository Wrtg for
EAS$3$1,Summer 2017$7981$EAS$1060$001$LEC$Expository Wrtg for
EAS$3$1]]".split(",")[0].split("$"));

      Array [ "[[Summer 2016", "7981", "EAS", "1060", "001", "LEC",
"Expository Wrtg for EAS", "3", "1" ]

console.log("[[Summer 2016$7981$EAS$1060$001$LEC$Expository Wrtg for
EAS$3$1,Summer 2017$7981$EAS$1060$001$LEC$Expository Wrtg for
EAS$3$1]]".split(",")[0].split("$")[0]);

      [[Summer 2016


So the '$' split delimiter doesn't seem a problem there. But that's
plain old browser Javascript, maybe the script engine version is
behaving differently or something.  Perhaps there the presence of the
special character '$' results in it autoconverting that to a Javascript
RegExp instance of something, and then that behaves differently.  Just
speculation.  This article suggests that in Javascript you escape that
special character like so: "\\$".

http://stackoverflow.com/questions/2168831/why-cant-i-split-a-string-with-the-dollar-sign


>
>
> However for some reason string winds up with the special char ‘[‘ and
> ‘]’…
>

Well, that's less of a mystery, I think. The "[[ .... ]]" showing up in
the initial string you are parsing is because of your 2 initial calls:

eduCourseOfferingTemp.getValues().add(uuenrl.getValues());

courses = eduCourseOfferingTemp.getValues().toString();


The outputs of the getValues() method calls there on our BasicAttribute
instances actually *are* Java List values.  And calling toString() on a
standard Java List instance results in a string like "[value1, value2,
..., valueN]". with literal brackets.

Btw, there is an implicit call to toString() on the argument of
.add(uuenrl.getValues()), b/c the add() takes a single object not a list.

So eduCourseOfferingTemp starts out there with a getValues() List with
a single string value that is wrapped in a single pair of literal
brackets. And then the second call wraps another pair of literal
brackets around that when it converts the whole list to a String.

I think you can eliminate the first pair of brackets by calling
.addAll(uuenrl.getValues()).  You can eliminate the second pair by
using something like a join() utility function or method to turn the
list into a string.  But I don't offhand know if you can use a Java
utility method there directly (we have one in java-support), or if you
have to use native Javascript, and how the latter works in the
scripting environment with the Java List type.  Maybe someone else knows.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/users/attachments/20160730/67b21985/attachment.html>


More information about the users mailing list