doc/coding_style.txt
author Jonas Schäfer <jonas@wielicki.name>
Mon, 10 Jan 2022 18:23:54 +0100
branch0.11
changeset 12185 783056b4e448
parent 8731 41c959c5c84b
permissions -rw-r--r--
util.xml: Do not allow doctypes, comments or processing instructions Yes. This is as bad as it sounds. CVE pending. In Prosody itself, this only affects mod_websocket, which uses util.xml to parse the <open/> frame, thus allowing unauthenticated remote DoS using Billion Laughs. However, third-party modules using util.xml may also be affected by this. This commit installs handlers which disallow the use of doctype declarations and processing instructions without any escape hatch. It, by default, also introduces such a handler for comments, however, there is a way to enable comments nontheless. This is because util.xml is used to parse human-facing data, where comments are generally a desirable feature, and also because comments are generally harmless.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     1
This file describes some coding styles to try and adhere to when contributing to this project.
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     2
Please try to follow, and feel free to fix code you see not following this standard.
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     3
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     4
== Indentation ==
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     5
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     6
	1 tab indentation for all blocks
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     7
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     8
== Spacing ==
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     9
8731
41c959c5c84b Fix spelling throughout the codebase [codespell]
Kim Alvefur <zash@zash.se>
parents: 13
diff changeset
    10
No space between function names and parenthesis and parenthesis and parameters:
13
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
		function foo(bar, baz)
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    13
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    14
Single space between braces and key/value pairs in table constructors:
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    15
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    16
		{ foo = "bar", bar = "foo" }
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    17
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    18
== Local variable naming ==
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    19
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
In this project there are many places where use of globals is restricted, and locals used for faster access.
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
Local versions of standard functions should follow the below form:
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
	math.random -> m_random
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    25
	string.char -> s_char	
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    26
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    27
== Miscellaneous ==
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    28
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    29
Single-statement blocks may be written on one line when short
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    30
	
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    31
	if foo then bar(); end
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    32
716632cca05d Coding style doc, HACKERS file
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    33
'do' and 'then' keywords should be placed at the end of the line, and never on a line by themself.