Skip to main content
tim_vt
Participant
December 16, 2015
Answered

Why is CRLF treated differently when called via bridgetalk?

  • December 16, 2015
  • 1 reply
  • 747 views

I bumped into yet another mystery: When I run a script directly in ExtendScript, it interpretes the '\r' as a CRLF. Yet, when I called it via bridgetalk, the '\r' was left as text.

This strange behavior exists if I set target to photoshop or not. Can someone tell me why please?

Below is the unit test (CS6, Windows 10)

- Calling script:

#target bridge

var bt = new BridgeTalk; 
bt.target = 'photoshop'; 
var myPath = '~/Desktop/testCarriageReturnSubstitution.jsx';
var scriptFile = new File(myPath);
var fOpen = scriptFile.open('r');
var script = scriptFile.read();
$.writeln(script);
bt.body =script;

bt.send();

- Test script:

#target photoshop

var badString = '\rTitle\rCity, State - USA   December 2015';

var newString = badString.replace('\n', "\n");

$.writeln (badString);

$.writeln(newString);

Result when running directly via ExtendScript:

Title

City, State - USA   December 2015

Result: undefined

Result when invoked via calling script:

Result: true

\rTitle\rCity, State - USA   December 2015

Thanks,

/Tim

This topic has been closed for replies.
Correct answer tim_vt

Thank you, Uwe for responding! I did try that before posting, and the result was '\\r'. It seems bridgetalk converts these escape characters to text.

I found another thread (Re: \n not working correctly)addressing the same issue, pointing way back to CS2 time! Wonder why Adobe did not fix the problem, and/or document this bug to save us some headache, or perhaps they documented it in some obscure place.

The workaround to the problem is to use decodeURI, and use hex code for these special characters. In my original unit test, I changed the photoshop script to the following:

#target photoshop
var Title = 'Title Text';
var CityState = 'San Francisco, California';
var badString = '\r'+Title+'\r'+CityState;
var goodString =  decodeURI(Title+"%0d"+CityState);

$.writeln ('Bad string encoding: ',badString);
$.writeln('Good string encoding: ',goodString);

Result:

Bad string encoding: \rTitle Text\rSan Francisco, California

Good string encoding: Title Text

San Francisco, California

1 reply

Community Expert
December 21, 2015

Hi Tim,

did you try to escape

\r

like that:

\\r

Uwe

tim_vt
tim_vtAuthorCorrect answer
Participant
December 23, 2015

Thank you, Uwe for responding! I did try that before posting, and the result was '\\r'. It seems bridgetalk converts these escape characters to text.

I found another thread (Re: \n not working correctly)addressing the same issue, pointing way back to CS2 time! Wonder why Adobe did not fix the problem, and/or document this bug to save us some headache, or perhaps they documented it in some obscure place.

The workaround to the problem is to use decodeURI, and use hex code for these special characters. In my original unit test, I changed the photoshop script to the following:

#target photoshop
var Title = 'Title Text';
var CityState = 'San Francisco, California';
var badString = '\r'+Title+'\r'+CityState;
var goodString =  decodeURI(Title+"%0d"+CityState);

$.writeln ('Bad string encoding: ',badString);
$.writeln('Good string encoding: ',goodString);

Result:

Bad string encoding: \rTitle Text\rSan Francisco, California

Good string encoding: Title Text

San Francisco, California