From 8e125cb7431db9383f4f0d1d3a4e9c7c7facdd96 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Fri, 19 Nov 2010 15:34:11 +0000 Subject: [PATCH] Fixed issue in the lifecycle generation tool (escape double quotes) SVN:trunk[950] --- pages/graphviz.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pages/graphviz.php b/pages/graphviz.php index 61116f98c..e77b651c6 100644 --- a/pages/graphviz.php +++ b/pages/graphviz.php @@ -32,6 +32,17 @@ require_once('../application/utils.inc.php'); require_once('../application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed +/** + * Escape a label (string) in a manner suitable for use with graphviz' DOT syntax + * @param string $s The string to escape + * @return string The escaped string + */ +function GraphvizEscape($s) +{ + $s = str_replace('"', '\\"', $s); + return $s; +} + /** * Helper to generate a Graphviz code for displaying the life cycle of a class * @param string $sClass The class to display @@ -71,7 +82,7 @@ function GraphvizLifecycle($sClass) $aStatesLinks[$aTransitionDef['target_state']]['in']++; $sStimulusLabel = $aStimuli[$sStimulusCode]->GetLabel(); $sTargetStateLabel = MetaModel::GetStateLabel($sClass, $aTransitionDef['target_state']); - $sDotFileContent .= "\t$sStateCode -> {$aTransitionDef['target_state']} [ label=\"$sStimulusLabel\"];\n"; + $sDotFileContent .= "\t$sStateCode -> {$aTransitionDef['target_state']} [ label=\"".GraphvizEscape($sStimulusLabel)."\"];\n"; } } foreach($aStates as $sStateCode => $aStateDef) @@ -83,11 +94,11 @@ function GraphvizLifecycle($sClass) if ( ($aStatesLinks[$sStateCode]['in'] == 0) || ($aStatesLinks[$sStateCode]['out'] == 0)) { // End or Start state, make it look different - $sDotFileContent .= "\t$sStateCode [ shape=doublecircle,label=\"$sStateLabel\"];\n"; + $sDotFileContent .= "\t$sStateCode [ shape=doublecircle,label=\"".GraphvizEscape($sStateLabel)."\"];\n"; } else { - $sDotFileContent .= "\t$sStateCode [ shape=circle,label=\"$sStateLabel\"];\n"; + $sDotFileContent .= "\t$sStateCode [ shape=circle,label=\"".GraphvizEscape($sStateLabel)."\"];\n"; } } }