Skip to content

Commit 638b616

Browse files
committed
Fix #4: Escape percent sign character.
1 parent 46308be commit 638b616

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

src/YawikXingVendorApi/Filter/XingData/Basic.php

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function filter($value)
7171
->setCompanyName($companyName)
7272
->setDisciplineId($disciplineId)
7373
->setCountry('DE')
74-
->setFunction($job->getTitle())
7574
->setIndustryId(isset($xingOpts['industry']) ? $xingOpts['industry'] : 230000)
7675
->setLanguage('de')
7776
->setReplySetting(XingData::REPLY_SETTINGS_EMAIL)

src/YawikXingVendorApi/Filter/XingData/Description.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function filter($value)
3737
$jobLink = $xingData->getPostingUrl();
3838
$description = $xingData->getDescription();
3939

40+
$title = $this->escapePercent($value->getJob()->getTitle());
41+
$logger && $logger->info('---> Set title to "' . $title . '"');
42+
$xingData->setFunction($title);
43+
4044
if (!$jobLink && !$description) {
4145
$logger && $logger->warn('No posting url in the Xing data object. Cannot fetch description.');
4246
return 'Missing posting_url. Cannot fetch description.';
@@ -81,8 +85,6 @@ public function filter($value)
8185
$stripTags->setAttributesAllowed(array());
8286
$description = trim(html_entity_decode($stripTags($dom->saveHTML())));
8387

84-
// Xing does not accept a '%' sign.
85-
$description = preg_replace('/%/','%',$description);
8688

8789
if (false === $description) {
8890
$data = $value->getData();
@@ -93,11 +95,18 @@ public function filter($value)
9395
$logger && $logger->notice('----> No description recieved. Fall back to transmitted description.');
9496
$return = 'Fetching description failed. Used transmitted description.';
9597
}
98+
// Xing does not accept a '%' sign.
99+
$description = $this->escapePercent($description);
100+
96101

97102
$xingData->setDescription($description);
98103

99104
return $return;
100105
}
101106

107+
private function escapePercent($str)
108+
{
109+
return str_replace('%', '\u0025', $str);
110+
}
102111

103-
}
112+
}

test/TestConfig.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
return array(
1212
// This should be an array of module namespaces used in the application.
13-
'modules' => array(
14-
'Core', 'Auth', 'Jobs', 'YawikXingVendorApi'
13+
'modules' => array_merge(
14+
include_once __DIR__.'/../../../config/common.modules.php',
15+
[ 'Core', 'Auth', 'Jobs', 'YawikXingVendorApi' ]
1516
),
1617

1718
// These are various options for the listeners attached to the ModuleManager

test/YawikXingVendorApiTest/Filter/XingData/DescriptionTest.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/** */
1111
namespace YawikXingVendorApiTest\Filter\XingData;
1212

13+
use Jobs\Entity\Job;
1314
use YawikXingVendorApi\Entity\XingData;
1415
use YawikXingVendorApi\Filter\XingData\Description;
1516
use YawikXingVendorApi\Filter\XingFilterData;
@@ -51,6 +52,19 @@ public function testImplementsZfFilterInterface()
5152
}
5253

5354

55+
public function testSetJobTitleInXingData()
56+
{
57+
$job = new Job();
58+
$job->setTitle('Test%Job');
59+
60+
$xingData = new XingData();
61+
$xingFilterData = new XingFilterData($xingData, null, [], $job);
62+
63+
$this->filter->filter($xingFilterData);
64+
65+
$this->assertEquals('Test\u0025Job', $xingData->getFunction());
66+
}
67+
5468
/**
5569
* Tests if attributes are stripped.
5670
*
@@ -74,19 +88,21 @@ public function testDescriptionWithAttributesInTags($input, $expected)
7488
*/
7589
public function provideHtml()
7690
{
91+
$job = new Job();
92+
$job->setTitle('TestJobTitle');
7793

7894
$xingData = new XingData();
7995
$xingData->setDescription('<p style="test">foobar</p>');
80-
$xingFilterData1 = new XingFilterData($xingData, null, [] ,null, null);
96+
$xingFilterData1 = new XingFilterData($xingData, null, [] ,$job, null);
8197

8298
$xingData = new XingData();
8399
$xingData->setDescription('<p style="test">foo % bar</p> replace % by entity');
84-
$xingFilterData2 = new XingFilterData($xingData, null, [] ,null, null);
100+
$xingFilterData2 = new XingFilterData($xingData, null, [] ,$job, null);
85101

86102

87103
return array(
88104
[$xingFilterData1,'<p>foobar</p>'],
89-
[$xingFilterData2,'<p>foo &percnt; bar</p> replace &percnt; by entity'],
105+
[$xingFilterData2,'<p>foo \u0025 bar</p> replace \u0025 by entity'],
90106
);
91107
}
92-
}
108+
}

0 commit comments

Comments
 (0)