Skip to content

Commit 2fa9595

Browse files
committed
Decode HTML entities in project files and library files before compilation
1 parent e48b6fe commit 2fa9595

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Symfony/src/Codebender/CompilerBundle/Handler/CompilerHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ function main($request, $compiler_config)
6767
$clang_target_arch = "-D".MCUHandler::$MCU[$mcu]." -DARDUINO=$version -DF_CPU=$f_cpu";
6868
$autocc_clang_target_arch = "-D".MCUHandler::$MCU[$mcu]." -DARDUINO=$version -DF_CPU=$f_cpu -DUSB_VID=$vid -DUSB_PID=$pid";
6969

70+
/*
71+
* Decode any HTML entities found in project/libraries files
72+
*/
73+
$request['files'] = $this->utility->htmlDecodeFiles($request['files']);
74+
$request['libraries'] = $this->utility->htmlDecodeLibraries($request['libraries']);
75+
7076
// Step 1(part 1): Extract the project files included in the request.
7177
$files = array();
7278
$tmpVar = $this->extractFiles($request["files"], $TEMP_DIR, $compiler_dir, $files["sketch_files"], "files");

Symfony/src/Codebender/CompilerBundle/Handler/UtilityHandler.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,47 @@ function execWithDebugging($command, /** @noinspection PhpUnusedParameterInspect
142142
echo "$ $command\n";
143143
passthru("$command 2>&1");
144144
}
145+
146+
/**
147+
* Decodes any HTML entities found in the list of provided files and returns the list of decoded
148+
* files. Each of the files should have the following format
149+
* ['filename' => filename, 'content' => code]
150+
*
151+
* @param $files
152+
* @return array
153+
*/
154+
function htmlDecodeFiles($files)
155+
{
156+
if (empty($files)) {
157+
return array();
158+
}
159+
160+
$htmlDecodedFiles = array();
161+
foreach ($files as $file) {
162+
$htmlDecodedFiles[] = array(
163+
'filename' => $file['filename'],
164+
'content' => htmlspecialchars_decode($file['content'])
165+
);
166+
}
167+
return $htmlDecodedFiles;
168+
}
169+
170+
/**
171+
* Applies the htmlDecodeFiles method to the files of each one of the provided libraries.
172+
*
173+
* @param $libraries
174+
* @return array
175+
*/
176+
function htmlDecodeLibraries($libraries)
177+
{
178+
if (empty($libraries)) {
179+
return array();
180+
}
181+
$htmlDecodedLibraries = array();
182+
foreach ($libraries as $libraryName => $libraryFiles) {
183+
$htmlDecodedLibraries[$libraryName] = $this->htmlDecodeFiles($libraryFiles);
184+
}
185+
186+
return $htmlDecodedLibraries;
187+
}
145188
}

0 commit comments

Comments
 (0)