def escape_jboss_attribute_expression(text):
    """
    Escapes text to make it safe for usage as value of JBoss configuration attribute which supports
    expression (https://docs.jboss.org/author/display/WFLY10/Expressions)
    """

    if text is None:
        return text
    s = str(text)
    # https://github.com/wildfly/wildfly-core/blob/7.0.0.Final/controller/src/main/java/org/jboss/as/controller/parsing/ParseUtils.java#L615
    open_idx = s.find('${')
    if -1 < open_idx < s.rfind('}'):
        # https://github.com/jbossas/jboss-dmr/blob/1.2.2.Final/src/main/java/org/jboss/dmr/ValueExpressionResolver.java#L78
        return s.replace('$', '$$')
    return s