서브메뉴

코딩 가이드라인

효율적 개발을 위한 PHP 코딩 가이드라인

범용 규범

특수 규범

문자열 escape 처리 지침
  • HTML, XHTML, XML의 모든 attribute value enclosure는 double quotes만을 사용한다.(왜냐하면, PHP 코딩 과정을 단순화하기 위해서입니다. single quotes도 지원하기 위해서는 htmlspecialchars() PHP함수에 ENT_QUOTES를 꼭 추가해 주어야 하기에 과정이나 차후 관리가 복잡해집니다.)
    <span title="hello"></span>          : YES
    <span title='hello'></span>           : NO!
  • 불필요한 경우에는 escape 처리를 하지 않는다. (escape할 character가 포함되지 않는 constant data 또는 variable value)
    <span><?=$entry['id']?></span>                                                : YES
    <span><?=htmlspecialchars($entry['subject'])?></span>            : YES
    <span><?=htmlspecialchars('hello')?></span>                           : NO!
    <span><?=htmlspecialchars($entry['id'])?></span>                    : NO!
  • XML(HTML) Element Text 또는 Attribute Value에 JavaScript 문자열의 일부가 아닌 경우는 htmlspecialchars()로 처리한다.
    <span><?=htmlspecialchars($entry['subject'])?></span>                                     : YES
    <span title="<?=htmlspecialchars($entry['subject'])?>"></span>                          : YES
    <span onclick="alert('<?=htmlspecialchars($entry['subject'])?>')"></span>            : NO!
  • XML(HTML) Attribute Value에 JavaScript 문자열의 일부인 경우는 escapeJSInAttribute()로 처리한다.
    <span onclick="alert('<?=escapeJSInAttribute($entry['subject'])?>')"></span>            : YES
    <span onclick="alert(<?=escapeJSInAttribute($entry['subject'])?>)"></span>            : NO!
    <span title="<?=escapeJSInAttribute($entry['subject'])?>"></span>                          : NO!
  • XML(HTML) CDATA Section Data에 JavaScript 문자열의 일부인 경우는 escapeJSInCData()로 처리한다.
    <script type="text/javascript>
    //<![CDATA[
    alert("<?=escapeJSInCData($entry['subject'])?>");                                              : YES
    alert(<?=escapeJSInCData($entry['subject'])?>);                                                : NO!
    alert("<?=htmlspecialchars($entry['subject'])?>");                                             : NO!
    alert("<?=escapeJSInAttribute($entry['subject'])?>");                                          : NO!
    document.getElementById("span1").title = "<?=escapeJSInCData($entry['subject'])?>";           : YES
    document.getElementById("span1").title = "<?=escapeJSInAttribute($entry['subject'])?>";        : NO!
    //]]>
    </script>

주석

  • 코드 관련 주석의 경우 검색의 용이성을 위하여 다음의 표기를 따릅니다.
    • TOKNOW - 앞으로 알아내야 할 부분
    • TEMPORARY - 임시로 구현한 부분
    • SUGGEST - 이러한 구현으로 제안하는 부분
    • DEPRECATE - 이곳에 있었던 코드는 폐기됨
  • 콜론(:) 앞에 물음표를 붙이면 다른 커미터의 의견을 묻는 내용입니다.

커밋 로그

  • 커밋 로그에는 반드시 ticket 번호를 기술해야합니다. 기술하는 방법은 다음과 같습니다.
    • 커밋이 티켓을 수정하는 경우: fix #nnnn
    • 커밋이 티켓을 참고하는 경우: refs #nnnn
    • 커밋이 티켓을 수정 및 종료하는 경우: close #nnnn
  • fix, see, close 는 다음과 같이 문맥에 맞추어 쓸 수도 있습니다.
    • fix -> fixed, fixes
    • refs -> references, re, see
    • close -> closed closes
  • 두 개 이상의 티켓에 연관되어 있는 경우 다음과 같이 ","를 사용하여 구분합니다.
    • refs #nnnn, #nnnn, #nnnn ...
    • fixes #nnnn, #nnnn, #nnnn ...
    • closes #nnnn, #nnnn, #nnnn ...

2008/02/13 21:30 2008/02/13 21:30
받은 트랙백이 없고   댓글이 없습니다.
이 글의 댓글/트랙백 RSS : http://textcube.org/manual/rss/response/17
이 글의 관련글(트랙백) 주소 : http://textcube.org/manual/trackback/17
Comments